home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / gpp-1_42.lha / g++-1.42.0 / stmt.c < prev    next >
C/C++ Source or Header  |  1991-10-19  |  159KB  |  5,068 lines

  1. /* Expands front end tree to back end RTL for GNU C-Compiler
  2.    Copyright (C) 1987, 1988, 1989 Free Software Foundation, Inc.
  3.  
  4. This file is part of GNU CC.
  5.  
  6. GNU CC is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 1, or (at your option)
  9. any later version.
  10.  
  11. GNU CC is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU CC; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20.  
  21. /* This file handles the generation of rtl code from tree structure
  22.    above the level of expressions, using subroutines in exp*.c and emit-rtl.c.
  23.    It also creates the rtl expressions for parameters and auto variables
  24.    and has full responsibility for allocating stack slots.
  25.  
  26.    The functions whose names start with `expand_' are called by the
  27.    parser to generate RTL instructions for various kinds of constructs.
  28.  
  29.    Some control and binding constructs require calling several such
  30.    functions at different times.  For example, a simple if-then
  31.    is expanded by calling `expand_start_cond' (with the condition-expression
  32.    as argument) before parsing the then-clause and calling `expand_end_cond'
  33.    after parsing the then-clause.
  34.  
  35.    `expand_function_start' is called at the beginning of a function,
  36.    before the function body is parsed, and `expand_function_end' is
  37.    called after parsing the body.
  38.  
  39.    Call `assign_stack_local' to allocate a stack slot for a local variable.
  40.    This is usually done during the RTL generation for the function body,
  41.    but it can also be done in the reload pass when a pseudo-register does
  42.    not get a hard register.
  43.  
  44.    Call `put_var_into_stack' when you learn, belatedly, that a variable
  45.    previously given a pseudo-register must in fact go in the stack.
  46.    This function changes the DECL_RTL to be a stack slot instead of a reg
  47.    then scans all the RTL instructions so far generated to correct them.  */
  48.  
  49. #include "config.h"
  50.  
  51. #include <stdio.h>
  52.  
  53. #include "rtl.h"
  54. #include "tree.h"
  55. #include "flags.h"
  56. #include "insn-flags.h"
  57. #include "insn-config.h"
  58. #include "insn-codes.h"
  59. #include "expr.h"
  60. #include "regs.h"
  61. #include "hard-reg-set.h"
  62. #include "recog.h"
  63. #include "obstack.h"
  64.  
  65. #define obstack_chunk_alloc xmalloc
  66. #define obstack_chunk_free free
  67. struct obstack stmt_obstack;
  68.  
  69. extern int xmalloc ();
  70. extern void free ();
  71.  
  72. #define MAX(x,y) (((x) > (y)) ? (x) : (y))
  73. #define MIN(x,y) (((x) < (y)) ? (x) : (y))
  74.  
  75. /* Nonzero if function being compiled pops its args on return.
  76.    May affect compilation of return insn or of function epilogue.  */
  77.  
  78. int current_function_pops_args;
  79.  
  80. /* Nonzero if function being compiled needs to be given an address
  81.    where the value should be stored.  */
  82.  
  83. int current_function_returns_struct;
  84.  
  85. /* Nonzero if function being compiled needs to
  86.    return the address of where it has put a structure value.  */
  87.  
  88. int current_function_returns_pcc_struct;
  89.  
  90. /* Nonzero if function being compiled needs to be passed a static chain.  */
  91.  
  92. int current_function_needs_context;
  93.  
  94. /* Nonzero if function being compiled can call setjmp.  */
  95.  
  96. int current_function_calls_setjmp;
  97.  
  98. /* Nonzero if function being compiled can call alloca,
  99.    either as a subroutine or builtin.  */
  100.  
  101. int current_function_calls_alloca;
  102.  
  103. /* Nonzero if the current function returns a pointer type */
  104.  
  105. int current_function_returns_pointer;
  106.  
  107. /* If function's args have a fixed size, this is that size, in bytes.
  108.    Otherwise, it is -1.
  109.    May affect compilation of return insn or of function epilogue.  */
  110.  
  111. int current_function_args_size;
  112.  
  113. /* # bytes the prologue should push and pretend that the caller pushed them.
  114.    The prologue must do this, but only if parms can be passed in registers.  */
  115.  
  116. int current_function_pretend_args_size;
  117.  
  118. /* This is the offset from the arg pointer to the place where the first
  119.    anonymous arg can be found, if there is one.  */
  120. rtx current_function_arg_offset_rtx;
  121.  
  122. /* Name of function now being compiled.  */
  123.  
  124. char *current_function_name;
  125.  
  126. /* Label that will go on parm cleanup code, if any.
  127.    Jumping to this label runs cleanup code for parameters, if
  128.    such code must be run.  Following this code is the logical return label.  */
  129.  
  130. rtx cleanup_label;
  131.  
  132. /* Label that will go on function epilogue.
  133.    Jumping to this label serves as a "return" instruction
  134.    on machines which require execution of the epilogue on all returns.  */
  135.  
  136. rtx return_label;
  137.  
  138. /* List (chain of EXPR_LISTs) of pseudo-regs of SAVE_EXPRs.
  139.    So we can mark them all live at the end of the function, if nonopt.  */
  140. rtx save_expr_regs;
  141.  
  142. /* List (chain of EXPR_LISTs) of all stack slots in this function.
  143.    Made for the sake of unshare_all_rtl.  */
  144. rtx stack_slot_list;
  145.  
  146. /* Filename and line number of last line-number note,
  147.    whether we actually emitted it or not.  */
  148. char *emit_filename;
  149. int emit_lineno;
  150.  
  151. /* Insn after which register parms and SAVE_EXPRs are born, if nonopt.  */
  152. static rtx parm_birth_insn;
  153.  
  154. /* The FUNCTION_DECL node for the function being compiled.  */
  155.  
  156. static tree this_function;
  157.  
  158. /* Number of binding contours started so far in this function.  */
  159.  
  160. static int block_start_count;
  161.  
  162. /* Offset to end of allocated area of stack frame.
  163.    If stack grows down, this is the address of the last stack slot allocated.
  164.    If stack grows up, this is the address for the next slot.  */
  165. static int frame_offset;
  166.  
  167. /* Nonzero if a stack slot has been generated whose address is not
  168.    actually valid.  It means that the generated rtl must all be scanned
  169.    to detect and correct the invalid addresses where they occur.  */
  170. static int invalid_stack_slot;
  171.  
  172. /* Label to jump back to for tail recursion, or 0 if we have
  173.    not yet needed one for this function.  */
  174. static rtx tail_recursion_label;
  175.  
  176. /* Place after which to insert the tail_recursion_label if we need one.  */
  177. static rtx tail_recursion_reentry;
  178.  
  179. /* Each time we expand an expression-statement,
  180.    record the expr's type and its RTL value here.  */
  181.  
  182. static tree last_expr_type;
  183. static rtx last_expr_value;
  184.  
  185. /* Chain of all RTL_EXPRs that have insns in them.  */
  186. static tree rtl_expr_chain;
  187.  
  188. /* Last insn of those whose job was to put parms into their nominal homes.  */
  189. static rtx last_parm_insn;
  190.  
  191. /* Functions and data structures for expanding case statements.  */
  192.  
  193. /* Case label structure, used to hold info on labels within case
  194.    statements.  We handle "range" labels; for a single-value label
  195.    as in C, the high and low limits are the same.  */
  196.  
  197. struct case_node
  198. {
  199.   struct case_node    *left;
  200.   struct case_node    *right;
  201.   struct case_node    *parent;
  202.   tree            low;
  203.   tree            high;
  204.   tree            test_label;
  205.   tree            code_label;
  206. };
  207.  
  208. typedef struct case_node case_node;
  209. typedef struct case_node *case_node_ptr;
  210.  
  211. extern void balance_case_nodes ();
  212. extern void emit_case_nodes ();
  213. extern void group_case_nodes ();
  214. extern void emit_jump_if_reachable ();
  215.  
  216. /* Stack of control and binding constructs we are currently inside.
  217.  
  218.    These constructs begin when you call `expand_start_WHATEVER'
  219.    and end when you call `expand_end_WHATEVER'.  This stack records
  220.    info about how the construct began that tells the end-function
  221.    what to do.  It also may provide information about the construct
  222.    to alter the behavior of other constructs within the body.
  223.    For example, they may affect the behavior of C `break' and `continue'.
  224.  
  225.    Each construct gets one `struct nesting' object.
  226.    All of these objects are chained through the `all' field.
  227.    `nesting_stack' points to the first object (innermost construct).
  228.    The position of an entry on `nesting_stack' is in its `depth' field.
  229.  
  230.    Each type of construct has its own individual stack.
  231.    For example, loops have `loop_stack'.  Each object points to the
  232.    next object of the same type through the `next' field.
  233.  
  234.    Some constructs are visible to `break' exit-statements and others
  235.    are not.  Which constructs are visible depends on the language.
  236.    Therefore, the data structure allows each construct to be visible
  237.    or not, according to the args given when the construct is started.
  238.    The construct is visible if the `exit_label' field is non-null.
  239.    In that case, the value should be a CODE_LABEL rtx.  */
  240.  
  241. struct nesting
  242. {
  243.   struct nesting *all;
  244.   struct nesting *next;
  245.   int depth;
  246.   rtx exit_label;
  247.   union
  248.     {
  249.       /* For conds (if-then and if-then-else statements).  */
  250.       struct
  251.     {
  252.       /* Label on the else-part, if any, else 0.  */
  253.       rtx else_label;
  254.       /* Label at the end of the whole construct.  */
  255.       rtx after_label;
  256.     } cond;
  257.       /* For loops.  */
  258.       struct
  259.     {
  260.       /* Label at the top of the loop; place to loop back to.  */
  261.       rtx start_label;
  262.       /* Label at the end of the whole construct.  */
  263.       rtx end_label;
  264.       /* Label for `continue' statement to jump to;
  265.          this is in front of the stepper of the loop.  */
  266.       rtx continue_label;
  267.     } loop;
  268.       /* For variable binding contours.  */
  269.       struct
  270.     {
  271.       /* Sequence number of this binding contour within the function,
  272.          in order of entry.  */
  273.       int block_start_count;
  274.       /* Nonzero => value to restore stack to on exit.  */
  275.       rtx stack_level;
  276.       /* The NOTE that starts this contour.
  277.          Used by expand_goto to check whether the destination
  278.          is within each contour or not.  */
  279.       rtx first_insn;
  280.       /* Innermost containing binding contour that has a stack level.  */
  281.       struct nesting *innermost_stack_block;
  282.       /* List of cleanups to be run on exit from this contour.
  283.          This is a list of expressions to be evaluated.
  284.          The TREE_PURPOSE of each link is the ..._DECL node
  285.          which the cleanup pertains to.  */
  286.       tree cleanups;
  287.       /* List of cleanup-lists of blocks containing this block,
  288.          as they were at the locus where this block appears.
  289.          There is an element for each containing block,
  290.          ordered innermost containing block first.
  291.          The element's TREE_VALUE is the cleanup-list of that block,
  292.          which may be null.  */
  293.       tree outer_cleanups;
  294.       /* Chain of labels defined inside this binding contour.
  295.          For contours that have stack levels or cleanups.  */
  296.       struct label_chain *label_chain;
  297.     } block;
  298.       /* For switch (C) or case (Pascal) statements,
  299.      and also for dummies (see `expand_start_case_dummy').  */
  300.       struct
  301.     {
  302.       /* The insn after which the case dispatch should finally
  303.          be emitted.  Zero for a dummy.  */
  304.       rtx start;
  305.       /* A list of case labels, kept in ascending order by value
  306.          as the list is built.
  307.          During expand_end_case, this list may be rearranged into a
  308.          nearly balanced binary tree.  */
  309.       struct case_node *case_list;
  310.       /* Label to jump to if no case matches.  */
  311.       tree default_label;
  312.       /* The expression to be dispatched on.  */
  313.       tree index_expr;
  314.       /* Type that INDEX_EXPR should be converted to.  */
  315.       tree nominal_type;
  316.       /* Number of range exprs in case statement.  */
  317.       short num_ranges;
  318.     } case_stmt;
  319.       /* For exception contours.  */
  320.       struct
  321.     {
  322.       /* List of exceptions raised.  This is a TREE_LIST
  323.          of whatever you want.  */
  324.       tree raised;
  325.       /* List of exceptions caught.  This is also a TREE_LIST
  326.          of whatever you want.  As a special case, it has the
  327.          value `void_type_node' if it handles default exceptions.  */
  328.       tree handled;
  329.  
  330.       /* First insn of TRY block, in case resumptive model is needed.  */
  331.       rtx first_insn;
  332.       /* Label for the catch clauses.  */
  333.       rtx except_label;
  334.       /* Label for unhandled exceptions.  */
  335.       rtx unhandled_label;
  336.       /* Label at the end of whole construct.  */
  337.       rtx after_label;
  338.       /* Label which "escapes" the exception construct.
  339.          Like EXIT_LABEL for BREAK construct, but for exceptions.  */
  340.       rtx escape_label;
  341.     } except_stmt;
  342.     } data;
  343. };
  344.  
  345. /* Chain of all pending binding contours.  */
  346. struct nesting *block_stack;
  347.  
  348. /* Chain of all pending binding contours that restore stack levels
  349.    or have cleanups.  */
  350. struct nesting *stack_block_stack;
  351.  
  352. /* Chain of all pending conditional statements.  */
  353. struct nesting *cond_stack;
  354.  
  355. /* Chain of all pending loops.  */
  356. struct nesting *loop_stack;
  357.  
  358. /* Chain of all pending case or switch statements.  */
  359. struct nesting *case_stack;
  360.  
  361. /* Chain of all pending exception contours.  */
  362. struct nesting *except_stack;
  363.  
  364. /* Separate chain including all of the above,
  365.    chained through the `all' field.  */
  366. struct nesting *nesting_stack;
  367.  
  368. /* Number of entries on nesting_stack now.  */
  369. int nesting_depth;
  370.  
  371. /* Pop one of the sub-stacks, such as `loop_stack' or `cond_stack';
  372.    and pop off `nesting_stack' down to the same level.  */
  373.  
  374. #define POPSTACK(STACK)                    \
  375. do { int initial_depth = nesting_stack->depth;        \
  376.      do { struct nesting *this = STACK;            \
  377.       STACK = this->next;                \
  378.       nesting_stack = this->all;            \
  379.       nesting_depth = this->depth;            \
  380.       obstack_free (&stmt_obstack, this); }        \
  381.      while (nesting_depth > initial_depth); } while (0)
  382.  
  383. static int warn_if_unused_value ();
  384. static void expand_goto_internal ();
  385. static int expand_fixup ();
  386. static void fixup_gotos ();
  387. static void expand_cleanups ();
  388. static void fixup_cleanups ();
  389. static void expand_null_return_1 ();
  390. static int tail_recursion_args ();
  391. static void fixup_stack_slots ();
  392. static rtx fixup_stack_1 ();
  393. static rtx fixup_memory_subreg ();
  394. static rtx walk_fixup_memory_subreg ();
  395. static void fixup_var_refs ();
  396. static void fixup_var_refs_insns ();
  397. static rtx fixup_var_refs_1 ();
  398. static rtx parm_stack_loc ();
  399. static void optimize_bit_field ();
  400. static void do_jump_if_equal ();
  401.  
  402. /* Emit a no-op instruction.  */
  403.  
  404. rtx
  405. emit_nop ()
  406. {
  407.   rtx last_insn = get_last_insn ();
  408.   if (!optimize
  409.       && (GET_CODE (last_insn) == CODE_LABEL
  410.       || prev_real_insn (last_insn) == 0))
  411.     emit_insn (gen_nop ());
  412. }
  413.  
  414. /* Return the rtx-label that corresponds to a LABEL_DECL,
  415.    creating it if necessary.  */
  416.  
  417. rtx /* @@ non-static for case.c.  */
  418. label_rtx (label)
  419.      tree label;
  420. {
  421.   if (TREE_CODE (label) != LABEL_DECL)
  422.     abort ();
  423.  
  424.   if (DECL_RTL (label))
  425.     return DECL_RTL (label);
  426.  
  427.   return DECL_RTL (label) = gen_label_rtx ();
  428. }
  429.  
  430. /* Add an unconditional jump to LABEL as the next sequential instruction.  */
  431.  
  432. void
  433. emit_jump (label)
  434.      rtx label;
  435. {
  436.   do_pending_stack_adjust ();
  437.   emit_jump_insn (gen_jump (label));
  438.   emit_barrier ();
  439. }
  440.  
  441. /* Handle goto statements and the labels that they can go to.  */
  442.  
  443. /* In some cases it is impossible to generate code for a forward goto 
  444.    until the label definition is seen.  This happens when it may be necessary
  445.    for the goto to reset the stack pointer: we don't yet know how to do that.
  446.    So expand_goto puts an entry on this fixup list.
  447.    Each time a binding contour that resets the stack is exited,
  448.    we check each fixup.
  449.    If the target label has now been defined, we can insert the proper code.  */
  450.  
  451. struct goto_fixup
  452. {
  453.   /* Points to following fixup.  */
  454.   struct goto_fixup *next;
  455.   /* Points to the insn before the jump insn.
  456.      If more code must be inserted, it goes after this insn.  */
  457.   rtx before_jump;
  458.   /* The LABEL_DECL that this jump is jumping to, or 0
  459.      for break, continue or return.  */
  460.   tree target;
  461.   /* The CODE_LABEL rtx that this is jumping to.  */
  462.   rtx target_rtl;
  463.   /* Number of binding contours started in current function
  464.      before the label reference.  */
  465.   int block_start_count;
  466.   /* The outermost stack level that should be restored for this jump.
  467.      Each time a binding contour that resets the stack is exited,
  468.      if the target label is *not* yet defined, this slot is updated.  */
  469.   rtx stack_level;
  470.   /* List of lists of cleanup expressions to be run by this goto.
  471.      There is one element for each block that this goto is within.
  472.      The TREE_VALUE contains the cleanup list of that block as of the
  473.      time this goto was seen.
  474.      The TREE_ADDRESSABLE flag is 1 for a block that has been exited.  */
  475.   tree cleanup_list_list;
  476. };
  477.  
  478. static struct goto_fixup *goto_fixup_chain;
  479.  
  480. /* Within any binding contour that must restore a stack level,
  481.    all labels are recorded with a chain of these structures.  */
  482.  
  483. struct label_chain
  484. {
  485.   /* Points to following fixup.  */
  486.   struct label_chain *next;
  487.   tree label;
  488. };
  489.  
  490. /* Specify the location in the RTL code of a label LABEL,
  491.    which is a LABEL_DECL tree node.
  492.  
  493.    This is used for the kind of label that the user can jump to with a
  494.    goto statement, and for alternatives of a switch or case statement.
  495.    RTL labels generated for loops and conditionals don't go through here;
  496.    they are generated directly at the RTL level, by other functions below.
  497.  
  498.    Note that this has nothing to do with defining label *names*.
  499.    Languages vary in how they do that and what that even means.  */
  500.  
  501. void
  502. expand_label (label)
  503.      tree label;
  504. {
  505.   struct label_chain *p;
  506.  
  507.   do_pending_stack_adjust ();
  508.   emit_label (label_rtx (label));
  509.  
  510.   if (stack_block_stack != 0)
  511.     {
  512.       p = (struct label_chain *) oballoc (sizeof (struct label_chain));
  513.       p->next = stack_block_stack->data.block.label_chain;
  514.       stack_block_stack->data.block.label_chain = p;
  515.       p->label = label;
  516.     }
  517. }
  518.  
  519. /* Generate RTL code for a `goto' statement with target label LABEL.
  520.    LABEL should be a LABEL_DECL tree node that was or will later be
  521.    defined with `expand_label'.  */
  522.  
  523. void
  524. expand_goto (label)
  525.      tree label;
  526. {
  527.   expand_goto_internal (label, label_rtx (label), 0);
  528. }
  529.  
  530. /* Generate RTL code for a `goto' statement with target label BODY.
  531.    LABEL should be a LABEL_REF.
  532.    LAST_INSN, if non-0, is the rtx we should consider as the last
  533.    insn emitted (for the purposes of cleaning up a return).  */
  534.  
  535. static void
  536. expand_goto_internal (body, label, last_insn)
  537.      tree body;
  538.      rtx label;
  539.      rtx last_insn;
  540. {
  541.   struct nesting *block;
  542.   rtx stack_level = 0;
  543.  
  544.   if (GET_CODE (label) != CODE_LABEL)
  545.     abort ();
  546.  
  547.   /* If label has already been defined, we can tell now
  548.      whether and how we must alter the stack level.  */
  549.  
  550.   if (PREV_INSN (label) != 0)
  551.     {
  552.       /* Find the innermost pending block that contains the label.
  553.      (Check containment by comparing insn-uids.)
  554.      Then restore the outermost stack level within that block,
  555.      and do cleanups of all blocks contained in it.  */
  556.       for (block = block_stack; block; block = block->next)
  557.     {
  558.       if (INSN_UID (block->data.block.first_insn) < INSN_UID (label))
  559.         break;
  560.       if (block->data.block.stack_level != 0)
  561.         stack_level = block->data.block.stack_level;
  562.       /* Execute the cleanups for blocks we are exiting.  */
  563.       if (block->data.block.cleanups != 0)
  564.         {
  565.           expand_cleanups (block->data.block.cleanups, 0);
  566.           do_pending_stack_adjust ();
  567.         }
  568.     }
  569.  
  570.       if (stack_level)
  571.     {
  572.       /* Ensure stack adjust isn't done by emit_jump, as this would clobber
  573.          the stack pointer.  This one should be deleted as dead by flow. */
  574.       clear_pending_stack_adjust ();
  575.       do_pending_stack_adjust ();
  576.       emit_move_insn (stack_pointer_rtx, stack_level);
  577.     }
  578.  
  579.       if (body != 0 && TREE_PACKED (body))
  580.     error ("jump to `%s' invalidly jumps into binding contour",
  581.            IDENTIFIER_POINTER (DECL_NAME (body)));
  582.     }
  583.   /* Label not yet defined: may need to put this goto
  584.      on the fixup list.  */
  585.   else if (! expand_fixup (body, label, last_insn))
  586.     {
  587.       /* No fixup needed.  Record that the label is the target
  588.      of at least one goto that has no fixup.  */
  589.       if (body != 0)
  590.     TREE_ADDRESSABLE (body) = 1;
  591.     }
  592.  
  593.   emit_jump (label);
  594. }
  595.  
  596. /* Generate if necessary a fixup for a goto
  597.    whose target label in tree structure (if any) is TREE_LABEL
  598.    and whose target in rtl is RTL_LABEL.
  599.  
  600.    If LAST_INSN is nonzero, we pretend that the jump appears
  601.    after insn LAST_INSN instead of at the current point in the insn stream.
  602.  
  603.    The fixup will be used later to insert insns at this point
  604.    to restore the stack level as appropriate for the target label.
  605.  
  606.    Value is nonzero if a fixup is made.  */
  607.  
  608. static int
  609. expand_fixup (tree_label, rtl_label, last_insn)
  610.      tree tree_label;
  611.      rtx rtl_label;
  612.      rtx last_insn;
  613. {
  614.   struct nesting *block, *end_block;
  615.  
  616.   /* See if we can recognize which block the label will be output in.
  617.      This is possible in some very common cases.
  618.      If we succeed, set END_BLOCK to that block.
  619.      Otherwise, set it to 0.  */
  620.  
  621.   if (cond_stack
  622.       && (rtl_label == cond_stack->data.cond.else_label
  623.       || rtl_label == cond_stack->data.cond.after_label))
  624.     end_block = cond_stack;
  625.   /* If we are in a loop, recognize certain labels which
  626.      are likely targets.  This reduces the number of fixups
  627.      we need to create.  */
  628.   else if (loop_stack
  629.       && (rtl_label == loop_stack->data.loop.start_label
  630.       || rtl_label == loop_stack->data.loop.end_label
  631.       || rtl_label == loop_stack->data.loop.continue_label))
  632.     end_block = loop_stack;
  633.   else
  634.     end_block = 0;
  635.  
  636.   /* Now set END_BLOCK to the binding level to which we will return.  */
  637.  
  638.   if (end_block)
  639.     {
  640.       struct nesting *next_block = end_block->all;
  641.       block = block_stack;
  642.  
  643.       /* First see if the END_BLOCK is inside the innermost binding level.
  644.      If so, then no cleanups or stack levels are relevant.  */
  645.       while (next_block && next_block != block)
  646.     next_block = next_block->all;
  647.  
  648.       if (next_block)
  649.     return 0;
  650.  
  651.       /* Otherwise, set END_BLOCK to the innermost binding level
  652.      which is outside the relevant control-structure nesting.  */
  653.       next_block = block_stack->next;
  654.       for (block = block_stack; block != end_block; block = block->all)
  655.     if (block == next_block)
  656.       next_block = next_block->next;
  657.       end_block = next_block;
  658.     }
  659.  
  660.   /* Does any containing block have a stack level or cleanups?
  661.      If not, no fixup is needed, and that is the normal case
  662.      (the only case, for standard C).  */
  663.   for (block = block_stack; block != end_block; block = block->next)
  664.     if (block->data.block.stack_level != 0
  665.     || block->data.block.cleanups != 0)
  666.       break;
  667.  
  668.   if (block != end_block)
  669.     {
  670.       /* Ok, a fixup is needed.  Add a fixup to the list of such.  */
  671.       struct goto_fixup *fixup
  672.     = (struct goto_fixup *) oballoc (sizeof (struct goto_fixup));
  673.       /* In case an old stack level is restored, make sure that comes
  674.      after any pending stack adjust.  */
  675.       /* ?? If the fixup isn't to come at the present position,
  676.      doing the stack adjust here isn't useful.  Doing it with our
  677.      settings at that location isn't useful either.  Let's hope
  678.      someone does it!  */
  679.       if (last_insn == 0)
  680.     do_pending_stack_adjust ();
  681.       fixup->before_jump = last_insn ? last_insn : get_last_insn ();
  682.       fixup->target = tree_label;
  683.       fixup->target_rtl = rtl_label;
  684.       fixup->block_start_count = block_start_count;
  685.       fixup->stack_level = 0;
  686.       fixup->cleanup_list_list
  687.     = (((block->data.block.outer_cleanups
  688. #if 0
  689.          && block->data.block.outer_cleanups != empty_cleanup_list
  690. #endif
  691.          )
  692.         || block->data.block.cleanups)
  693.        ? tree_cons (0, block->data.block.cleanups,
  694.             block->data.block.outer_cleanups)
  695.        : 0);
  696.       fixup->next = goto_fixup_chain;
  697.       goto_fixup_chain = fixup;
  698.     }
  699.  
  700.   return block != 0;
  701. }
  702.  
  703. /* When exiting a binding contour, process all pending gotos requiring fixups.
  704.    THISBLOCK is the structure that describes the block being exited.
  705.    STACK_LEVEL is the rtx for the stack level to restore exiting this contour.
  706.    CLEANUP_LIST is a list of expressions to evaluate on exiting this contour.
  707.    FIRST_INSN is the insn that began this contour.
  708.  
  709.    Gotos that jump out of this contour must restore the
  710.    stack level and do the cleanups before actually jumping.
  711.  
  712.    DONT_JUMP_IN nonzero means report error there is a jump into this
  713.    contour from before the beginning of the contour.
  714.    This is also done if STACK_LEVEL is nonzero.  */
  715.  
  716. static void
  717. fixup_gotos (thisblock, stack_level, cleanup_list, first_insn, dont_jump_in)
  718.      struct nesting *thisblock;
  719.      rtx stack_level;
  720.      tree cleanup_list;
  721.      rtx first_insn;
  722.      int dont_jump_in;
  723. {
  724.   register struct goto_fixup *f, *prev;
  725.  
  726.   /* F is the fixup we are considering; PREV is the previous one.  */
  727.   /* We run this loop in two passes so that cleanups of exited blocks
  728.      are run first, and blocks that are exited are marked so
  729.      afterwards.  */
  730.  
  731.   for (prev = 0, f = goto_fixup_chain; f; prev = f, f = f->next)
  732.     {
  733.       /* Test for a fixup that is inactive because it is already handled.  */
  734.       if (f->before_jump == 0)
  735.     {
  736.       /* Delete inactive fixup from the chain, if that is easy to do.  */
  737.       if (prev != 0)
  738.         prev->next = f->next;
  739.     }
  740.       /* Has this fixup's target label been defined?
  741.      If so, we can finalize it.  */
  742.       else if (PREV_INSN (f->target_rtl) != 0)
  743.     {
  744.       /* Get the first non-label after the label
  745.          this goto jumps to.  If that's before this scope begins,
  746.          we don't have a jump into the scope.  */
  747.       rtx after_label = f->target_rtl;
  748.       while (after_label != 0 && GET_CODE (after_label) == CODE_LABEL)
  749.         after_label = NEXT_INSN (after_label);
  750.  
  751.       /* If this fixup jumped into this contour from before the beginning
  752.          of this contour, report an error.  */
  753.       /* ??? Bug: this does not detect jumping in through intermediate
  754.          blocks that have stack levels or cleanups.
  755.          It detects only a problem with the innermost block
  756.          around the label.  */
  757.       if (f->target != 0
  758.           && (dont_jump_in || stack_level || cleanup_list)
  759.           /* If AFTER_LABEL is 0, it means the jump goes to the end
  760.          of the rtl, which means it jumps into this scope.  */
  761.           && (after_label == 0
  762.           || INSN_UID (first_insn) < INSN_UID (after_label))
  763.           && INSN_UID (first_insn) > INSN_UID (f->before_jump)
  764.           && ! TREE_REGDECL (f->target))
  765.         {
  766.           error_with_decl (f->target,
  767.                    "label `%s' used before containing binding contour");
  768.           /* Prevent multiple errors for one label.  */
  769.           TREE_REGDECL (f->target) = 1;
  770.         }
  771.  
  772.       /* Execute cleanups for blocks this jump exits.  */
  773.       if (f->cleanup_list_list)
  774.         {
  775.           tree lists;
  776.           for (lists = f->cleanup_list_list; lists; lists = TREE_CHAIN (lists))
  777.         /* Marked elements correspond to blocks that have been closed.
  778.            Do their cleanups.  */
  779.         if (TREE_ADDRESSABLE (lists)
  780.             && TREE_VALUE (lists) != 0)
  781.           fixup_cleanups (TREE_VALUE (lists), &f->before_jump);
  782.         }
  783.  
  784.       /* Restore stack level for the biggest contour that this
  785.          jump jumps out of.  */
  786.       if (f->stack_level)
  787.         emit_insn_after (gen_move_insn (stack_pointer_rtx, f->stack_level),
  788.                  f->before_jump);
  789.       f->before_jump = 0;
  790.     }
  791.     }
  792.  
  793.   /* Mark the cleanups of exited blocks so that they are executed
  794.      by the code above.  */
  795.   for (prev = 0, f = goto_fixup_chain; f; prev = f, f = f->next)
  796.     if (f->before_jump != 0
  797.     && PREV_INSN (f->target_rtl) == 0
  798.     /* Label has still not appeared.  If we are exiting a block with
  799.        a stack level to restore, that started before the fixup,
  800.        mark this stack level as needing restoration
  801.        when the fixup is later finalized.
  802.        Also mark the cleanup_list_list element for F
  803.        that corresponds to this block, so that ultimately
  804.        this block's cleanups will be executed by the code above.  */
  805.     && thisblock != 0
  806.     /* Note: if THISBLOCK == 0 and we have a label that hasn't appeared,
  807.        it means the label is undefined.  That's erroneous, but possible.  */
  808.     && (thisblock->data.block.block_start_count
  809.         <= f->block_start_count))
  810.       {
  811.     tree lists = f->cleanup_list_list;
  812.     for (; lists; lists = TREE_CHAIN (lists))
  813.       /* If the following elt. corresponds to our containing block
  814.          then the elt. must be for this block.  */
  815.       if (TREE_CHAIN (lists) == thisblock->data.block.outer_cleanups)
  816.         TREE_ADDRESSABLE (lists) = 1;
  817.  
  818.     if (stack_level)
  819.       f->stack_level = stack_level;
  820.       }
  821. }
  822.  
  823. /* Generate RTL for an asm statement (explicit assembler code).
  824.    BODY is a STRING_CST node containing the assembler code text.  */
  825.  
  826. void
  827. expand_asm (body)
  828.      tree body;
  829. {
  830.   emit_insn (gen_rtx (ASM_INPUT, VOIDmode,
  831.               TREE_STRING_POINTER (body)));
  832.   last_expr_type = 0;
  833. }
  834.  
  835. /* Generate RTL for an asm statement with arguments.
  836.    STRING is the instruction template.
  837.    OUTPUTS is a list of output arguments (lvalues); INPUTS a list of inputs.
  838.    Each output or input has an expression in the TREE_VALUE and
  839.    a constraint-string in the TREE_PURPOSE.
  840.    CLOBBERS is a list of STRING_CST nodes each naming a hard register
  841.    that is clobbered by this insn.
  842.  
  843.    Not all kinds of lvalue that may appear in OUTPUTS can be stored directly.
  844.    Some elements of OUTPUTS may be replaced with trees representing temporary
  845.    values.  The caller should copy those temporary values to the originally
  846.    specified lvalues.
  847.  
  848.    VOL nonzero means the insn is volatile; don't optimize it.  */
  849.  
  850. void
  851. expand_asm_operands (string, outputs, inputs, clobbers, vol, filename, line)
  852.      tree string, outputs, inputs, clobbers;
  853.      int vol;
  854.      char *filename;
  855.      int line;
  856. {
  857.   rtvec argvec, constraints;
  858.   rtx body;
  859.   int ninputs = list_length (inputs);
  860.   int noutputs = list_length (outputs);
  861.   int nclobbers = list_length (clobbers);
  862.   tree tail;
  863.   register int i;
  864.   /* Vector of RTX's of evaluated output operands.  */
  865.   rtx *output_rtx = (rtx *) alloca (noutputs * sizeof (rtx));
  866.   /* The insn we have emitted.  */
  867.   rtx insn;
  868.  
  869.   last_expr_type = 0;
  870.  
  871.   for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  872.     {
  873.       tree val = TREE_VALUE (tail);
  874.       tree val1;
  875.       int j;
  876.       int found_equal;
  877.  
  878.       /* If there's an erroneous arg, emit no insn.  */
  879.       if (TREE_TYPE (val) == error_mark_node)
  880.     return;
  881.  
  882.       /* Make sure constraint has `=' and does not have `+'.  */
  883.  
  884.       found_equal = 0;
  885.       for (j = 0; j < TREE_STRING_LENGTH (TREE_PURPOSE (tail)); j++)
  886.     {
  887.       if (TREE_STRING_POINTER (TREE_PURPOSE (tail))[j] == '+')
  888.         {
  889.           error ("output operand constraint contains `+'");
  890.           return;
  891.         }
  892.       if (TREE_STRING_POINTER (TREE_PURPOSE (tail))[j] == '=')
  893.         found_equal = 1;
  894.     }
  895.       if (! found_equal)
  896.     {
  897.       error ("output operand constraint lacks `='");
  898.       return;
  899.     }
  900.  
  901.       /* If an output operand is not a variable or indirect ref,
  902.      or a part of one,
  903.      create a SAVE_EXPR which is a pseudo-reg
  904.      to act as an intermediate temporary.
  905.      Make the asm insn write into that, then copy it to
  906.      the real output operand.  */
  907.  
  908.       while (TREE_CODE (val) == COMPONENT_REF
  909.          || TREE_CODE (val) == ARRAY_REF)
  910.     val = TREE_OPERAND (val, 0);
  911.  
  912.       if (TREE_CODE (val) != VAR_DECL
  913.       && TREE_CODE (val) != PARM_DECL
  914.       && TREE_CODE (val) != INDIRECT_REF)
  915.     TREE_VALUE (tail) = save_expr (TREE_VALUE (tail));
  916.  
  917.       output_rtx[i] = expand_expr (TREE_VALUE (tail), 0, VOIDmode, 0);
  918.     }
  919.  
  920.   if (ninputs + noutputs > MAX_RECOG_OPERANDS)
  921.     {
  922.       error ("more than %d operands in `asm'", MAX_RECOG_OPERANDS);
  923.       return;
  924.     }
  925.  
  926.   /* Make vectors for the expression-rtx and constraint strings.  */
  927.  
  928.   argvec = rtvec_alloc (ninputs);
  929.   constraints = rtvec_alloc (ninputs);
  930.  
  931.   body = gen_rtx (ASM_OPERANDS, VOIDmode,
  932.           TREE_STRING_POINTER (string), "", 0, argvec, constraints,
  933.           filename, line);
  934.   MEM_VOLATILE_P (body) = vol;
  935.  
  936.   /* Eval the inputs and put them into ARGVEC.
  937.      Put their constraints into ASM_INPUTs and store in CONSTRAINTS.  */
  938.  
  939.   i = 0;
  940.   for (tail = inputs; tail; tail = TREE_CHAIN (tail))
  941.     {
  942.       int j;
  943.  
  944.       /* If there's an erroneous arg, emit no insn,
  945.      because the ASM_INPUT would get VOIDmode
  946.      and that could cause a crash in reload.  */
  947.       if (TREE_TYPE (TREE_VALUE (tail)) == error_mark_node)
  948.     return;
  949.       if (TREE_PURPOSE (tail) == NULL_TREE)
  950.     {
  951.       error ("hard register `%s' listed as input operand to `asm'",
  952.          TREE_STRING_POINTER (TREE_VALUE (tail)) );
  953.       return;
  954.     }
  955.  
  956.       /* Make sure constraint has neither `=' nor `+'.  */
  957.  
  958.       for (j = 0; j < TREE_STRING_LENGTH (TREE_PURPOSE (tail)); j++)
  959.     if (TREE_STRING_POINTER (TREE_PURPOSE (tail))[j] == '='
  960.         || TREE_STRING_POINTER (TREE_PURPOSE (tail))[j] == '+')
  961.       {
  962.         error ("input operand constraint contains `%c'",
  963.            TREE_STRING_POINTER (TREE_PURPOSE (tail))[j]);
  964.         return;
  965.       }
  966.  
  967.       XVECEXP (body, 3, i)      /* argvec */
  968.     = expand_expr (TREE_VALUE (tail), 0, VOIDmode, 0);
  969.       XVECEXP (body, 4, i)      /* constraints */
  970.     = gen_rtx (ASM_INPUT, TYPE_MODE (TREE_TYPE (TREE_VALUE (tail))),
  971.            TREE_STRING_POINTER (TREE_PURPOSE (tail)));
  972.       i++;
  973.     }
  974.  
  975.   /* Protect all the operands from the queue,
  976.      now that they have all been evaluated.  */
  977.  
  978.   for (i = 0; i < ninputs; i++)
  979.     XVECEXP (body, 3, i) = protect_from_queue (XVECEXP (body, 3, i), 0);
  980.  
  981.   for (i = 0; i < noutputs; i++)
  982.     output_rtx[i] = protect_from_queue (output_rtx[i], 1);
  983.  
  984.   /* Now, for each output, construct an rtx
  985.      (set OUTPUT (asm_operands INSN OUTPUTNUMBER OUTPUTCONSTRAINT
  986.                    ARGVEC CONSTRAINTS))
  987.      If there is more than one, put them inside a PARALLEL.  */
  988.  
  989.   if (noutputs == 1 && nclobbers == 0)
  990.     {
  991.       XSTR (body, 1) = TREE_STRING_POINTER (TREE_PURPOSE (outputs));
  992.       insn = emit_insn (gen_rtx (SET, VOIDmode, output_rtx[0], body));
  993.     }
  994.   else if (noutputs == 0 && nclobbers == 0)
  995.     {
  996.       /* No output operands: put in a raw ASM_OPERANDS rtx.  */
  997.       insn = emit_insn (body);
  998.     }
  999.   else
  1000.     {
  1001.       rtx obody = body;
  1002.       int num = noutputs;
  1003.       if (num == 0) num = 1;
  1004.       body = gen_rtx (PARALLEL, VOIDmode, rtvec_alloc (num + nclobbers));
  1005.  
  1006.       /* For each output operand, store a SET.  */
  1007.  
  1008.       for (i = 0, tail = outputs; tail; tail = TREE_CHAIN (tail), i++)
  1009.     {
  1010.       XVECEXP (body, 0, i)
  1011.         = gen_rtx (SET, VOIDmode,
  1012.                output_rtx[i],
  1013.                gen_rtx (ASM_OPERANDS, VOIDmode,
  1014.                 TREE_STRING_POINTER (string),
  1015.                 TREE_STRING_POINTER (TREE_PURPOSE (tail)),
  1016.                 i, argvec, constraints,
  1017.                 filename, line));
  1018.       MEM_VOLATILE_P (SET_SRC (XVECEXP (body, 0, i))) = vol;
  1019.     }
  1020.  
  1021.       /* If there are no outputs (but there are some clobbers)
  1022.      store the bare ASM_OPERANDS into the PARALLEL.  */
  1023.  
  1024.       if (i == 0)
  1025.     XVECEXP (body, 0, i++) = obody;
  1026.  
  1027.       /* Store (clobber REG) for each clobbered register specified.  */
  1028.  
  1029.       for (tail = clobbers; tail; tail = TREE_CHAIN (tail), i++)
  1030.     {
  1031.       int j;
  1032.       char *regname = TREE_STRING_POINTER (TREE_VALUE (tail));
  1033.       extern char *reg_names[];
  1034.           
  1035.       for (j = 0; j < FIRST_PSEUDO_REGISTER; j++)
  1036.         if (!strcmp (regname, reg_names[j]))
  1037.           break;
  1038.           
  1039.       if (j == FIRST_PSEUDO_REGISTER)
  1040.         {
  1041.           error ("unknown register name `%s' in `asm'", regname);
  1042.           return;
  1043.         }
  1044.  
  1045.       /* Use QImode since that's guaranteed to clobber just one reg.  */
  1046.       XVECEXP (body, 0, i)
  1047.         = gen_rtx (CLOBBER, VOIDmode, gen_rtx (REG, QImode, j));
  1048.     }
  1049.  
  1050.       insn = emit_insn (body);
  1051.     }
  1052.  
  1053.   last_expr_type = 0;
  1054. }
  1055.  
  1056. /* Nonzero if within a ({...}) grouping, in which case we must
  1057.    always compute a value for each expr-stmt in case it is the last one.  */
  1058.  
  1059. int expr_stmts_for_value;
  1060.  
  1061. /* Generate RTL to evaluate the expression EXP
  1062.    and remember it in case this is the VALUE in a ({... VALUE; }) constr.  */
  1063.  
  1064. void
  1065. expand_expr_stmt (exp)
  1066.      tree exp;
  1067. {
  1068.   /* If -W, warn about statements with no side effects,
  1069.      except for statements explicitly casted to void (e.g. for assert()), and
  1070.      except inside a ({...}) where they may be useful.  */
  1071.   if (expr_stmts_for_value == 0 && exp != error_mark_node)
  1072.     {
  1073.       if (! TREE_VOLATILE (exp)
  1074.       && !(TREE_CODE (exp) == CONVERT_EXPR
  1075.            && TREE_TYPE (exp) == void_type_node)
  1076.       && (extra_warnings || warn_unused))
  1077.     warning_with_file_and_line (emit_filename, emit_lineno,
  1078.                     "statement with no effect");
  1079.       else if (warn_unused)
  1080.     warn_if_unused_value (exp);
  1081.     }
  1082.   last_expr_type = TREE_TYPE (exp);
  1083.   if (! flag_syntax_only)
  1084.     last_expr_value = expand_expr (exp, expr_stmts_for_value ? 0 : const0_rtx,
  1085.                    VOIDmode, 0);
  1086.   emit_queue ();
  1087. }
  1088.  
  1089. /* Warn if EXP contains any computations whose results are not used.
  1090.    Return 1 if a warning is printed; 0 otherwise.  */
  1091.  
  1092. static int
  1093. warn_if_unused_value (exp)
  1094.      tree exp;
  1095. {
  1096.   if (TREE_USED (exp))
  1097.     return 0;
  1098.  
  1099.   switch (TREE_CODE (exp))
  1100.     {
  1101.     case PREINCREMENT_EXPR:
  1102.     case POSTINCREMENT_EXPR:
  1103.     case PREDECREMENT_EXPR:
  1104.     case POSTDECREMENT_EXPR:
  1105.     case MODIFY_EXPR:
  1106.     case INIT_EXPR:
  1107.     case NEW_EXPR:
  1108.     case CALL_EXPR:
  1109.     case METHOD_CALL_EXPR:
  1110.     case RTL_EXPR:
  1111.     case WRAPPER_EXPR:
  1112.     case ANTI_WRAPPER_EXPR:
  1113.     case WITH_CLEANUP_EXPR:
  1114.       /* We don't warn about COND_EXPR because it may be a useful
  1115.      construct if either arm contains a side effect.  */
  1116.     case COND_EXPR:
  1117.       return 0;
  1118.  
  1119.       /* These kinds of exprs are really stmts.  What to do?  */
  1120.     case LOOP_STMT:
  1121.     case LET_STMT:
  1122.     case IF_STMT:
  1123.       return 0;
  1124.  
  1125.     case TRUTH_ORIF_EXPR:
  1126.     case TRUTH_ANDIF_EXPR:
  1127.       /* In && or ||, warn if 2nd operand has no side effect.  */
  1128.       return warn_if_unused_value (TREE_OPERAND (exp, 1));
  1129.  
  1130.     case COMPOUND_EXPR:
  1131.       if (warn_if_unused_value (TREE_OPERAND (exp, 0)))
  1132.     return 1;
  1133.       return warn_if_unused_value (TREE_OPERAND (exp, 1));
  1134.  
  1135.     case NOP_EXPR:
  1136.     case CONVERT_EXPR:
  1137.       /* Don't warn about values cast to void.  */
  1138.       if (TREE_TYPE (exp) == void_type_node)
  1139.     return 0;
  1140.       /* Assignment to a cast results in a cast of a modify.
  1141.      Don't complain about that.  */
  1142.       if (TREE_CODE (TREE_OPERAND (exp, 0)) == MODIFY_EXPR)
  1143.     return 0;
  1144.       /* Sometimes it results in a cast of a cast of a modify.
  1145.      Don't complain about that.  */
  1146.       if ((TREE_CODE (TREE_OPERAND (exp, 0)) == CONVERT_EXPR
  1147.        || TREE_CODE (TREE_OPERAND (exp, 0)) == NOP_EXPR)
  1148.       && TREE_CODE (TREE_OPERAND (TREE_OPERAND (exp, 0), 0)) == MODIFY_EXPR)
  1149.     return 0;
  1150.  
  1151.     default:
  1152.       warning_with_file_and_line (emit_filename, emit_lineno,
  1153.                   "value computed is not used");
  1154.       return 1;
  1155.     }
  1156. }
  1157.  
  1158. /* Clear out the memory of the last expression evaluated.  */
  1159.  
  1160. void
  1161. clear_last_expr ()
  1162. {
  1163.   last_expr_type = 0;
  1164. }
  1165.  
  1166. /* Begin a statement which will return a value.
  1167.    Return the RTL_EXPR for this statement expr.
  1168.    The caller must save that value and pass it to expand_end_stmt_expr.  */
  1169.  
  1170. tree
  1171. expand_start_stmt_expr ()
  1172. {
  1173.   rtx save = start_sequence ();
  1174.   /* Make the RTL_EXPR node temporary, not momentary,
  1175.      so that rtl_expr_chain doesn't become garbage.  */
  1176.   int momentary = suspend_momentary ();
  1177.   tree t = make_node (RTL_EXPR);
  1178.   resume_momentary (momentary);
  1179.   RTL_EXPR_RTL (t) = save;
  1180.   NO_DEFER_POP;
  1181.   expr_stmts_for_value++;
  1182.   return t;
  1183. }
  1184.  
  1185. /* Restore the previous state at the end of a statement that returns a value.
  1186.    Returns a tree node representing the statement's value and the
  1187.    insns to compute the value.
  1188.  
  1189.    The nodes of that expression have been freed by now, so we cannot use them.
  1190.    But we don't want to do that anyway; the expression has already been
  1191.    evaluated and now we just want to use the value.  So generate a RTL_EXPR
  1192.    with the proper type and RTL value.
  1193.  
  1194.    If the last substatement was not an expression,
  1195.    return something with type `void'.  */
  1196.  
  1197. tree
  1198. expand_end_stmt_expr (t)
  1199.      tree t;
  1200. {
  1201.   rtx saved = RTL_EXPR_RTL (t);
  1202.  
  1203.   OK_DEFER_POP;
  1204.  
  1205.   if (last_expr_type == 0)
  1206.     {
  1207.       last_expr_type = void_type_node;
  1208.       last_expr_value = const0_rtx;
  1209.     }
  1210.   TREE_TYPE (t) = last_expr_type;
  1211.   RTL_EXPR_RTL (t) = last_expr_value;
  1212.   RTL_EXPR_SEQUENCE (t) = get_insns ();
  1213.  
  1214.   rtl_expr_chain = tree_cons (NULL_TREE, t, rtl_expr_chain);
  1215.  
  1216.   end_sequence (saved);
  1217.  
  1218.   /* Don't consider deleting this expr or containing exprs at tree level.  */
  1219.   TREE_VOLATILE (t) = 1;
  1220.   /* Propagate volatility of the actual RTL expr.  */
  1221.   TREE_THIS_VOLATILE (t) = volatile_refs_p (last_expr_value);
  1222.  
  1223.   last_expr_type = 0;
  1224.   expr_stmts_for_value--;
  1225.  
  1226.   return t;
  1227. }
  1228.  
  1229. /* The exception handling nesting looks like this:
  1230.  
  1231.         <-- Level N-1
  1232.     {        <-- exception handler block
  1233.         <-- Level N
  1234.         <-- in an exception handler
  1235.     {    <-- try block
  1236.     :    <-- in a TRY block
  1237.     :    <-- in an exception handler
  1238.     :
  1239.     }
  1240.  
  1241.     {    <-- except block
  1242.     :    <-- in an except block
  1243.     :    <-- in an exception handler
  1244.     :
  1245.     }
  1246.  
  1247.     }
  1248.  
  1249. /* Return nonzero iff in a try block at level LEVEL.  */
  1250.  
  1251. int
  1252. in_try_block (level)
  1253.      int level;
  1254. {
  1255.   struct nesting *n = except_stack;
  1256.   while (1)
  1257.     {
  1258.       while (n && n->data.except_stmt.after_label != 0)
  1259.     n = n->next;
  1260.       if (n == 0)
  1261.     return 0;
  1262.       if (level == 0)
  1263.     return n != 0;
  1264.       level--;
  1265.       n = n->next;
  1266.     }
  1267. }
  1268.  
  1269. /* Return nonzero iff in an except block at level LEVEL.  */
  1270.  
  1271. int
  1272. in_except_block (level)
  1273.      int level;
  1274. {
  1275.   struct nesting *n = except_stack;
  1276.   while (1)
  1277.     {
  1278.       while (n && n->data.except_stmt.after_label == 0)
  1279.     n = n->next;
  1280.       if (n == 0)
  1281.     return 0;
  1282.       if (level == 0)
  1283.     return n != 0;
  1284.       level--;
  1285.       n = n->next;
  1286.     }
  1287. }
  1288.  
  1289. /* Return nonzero iff in an exception handler at level LEVEL.  */
  1290.  
  1291. int
  1292. in_exception_handler (level)
  1293.      int level;
  1294. {
  1295.   struct nesting *n = except_stack;
  1296.   while (n && level--)
  1297.     n = n->next;
  1298.   return n != 0;
  1299. }
  1300.  
  1301. /* Record the fact that the current exception nesting raises
  1302.    exception EX.  If not in an exception handler, return 0.  */
  1303. int
  1304. expand_raise (ex)
  1305.      tree ex;
  1306. {
  1307.   tree *raises_ptr;
  1308.  
  1309.   if (except_stack == 0)
  1310.     return 0;
  1311.   raises_ptr = &except_stack->data.except_stmt.raised;
  1312.   if (! value_member (ex, *raises_ptr))
  1313.     *raises_ptr = tree_cons (NULL_TREE, ex, *raises_ptr);
  1314.   return 1;
  1315. }
  1316.  
  1317. /* Generate RTL for the start of a try block.
  1318.  
  1319.    TRY_CLAUSE is the condition to test to enter the try block.  */
  1320.  
  1321. void
  1322. expand_start_try (try_clause, exitflag, escapeflag)
  1323.      tree try_clause;
  1324.      int exitflag;
  1325.      int escapeflag;
  1326. {
  1327.   struct nesting *thishandler
  1328.     = (struct nesting *) obstack_alloc (&stmt_obstack, sizeof (struct nesting));
  1329.  
  1330.   /* Make an entry on cond_stack for the cond we are entering.  */
  1331.  
  1332.   thishandler->next = except_stack;
  1333.   thishandler->all = nesting_stack;
  1334.   thishandler->depth = ++nesting_depth;
  1335.   thishandler->data.except_stmt.raised = 0;
  1336.   thishandler->data.except_stmt.handled = 0;
  1337.   thishandler->data.except_stmt.first_insn = get_insns ();
  1338.   thishandler->data.except_stmt.except_label = gen_label_rtx ();
  1339.   thishandler->data.except_stmt.unhandled_label = 0;
  1340.   thishandler->data.except_stmt.after_label = 0;
  1341.   thishandler->data.except_stmt.escape_label
  1342.     = escapeflag ? thishandler->data.except_stmt.except_label : 0;
  1343.   thishandler->exit_label = exitflag ? gen_label_rtx () : 0;
  1344.   except_stack = thishandler;
  1345.   nesting_stack = thishandler;
  1346.  
  1347.   do_jump (try_clause, thishandler->data.except_stmt.except_label, NULL);
  1348. }
  1349.  
  1350. /* End of a TRY block.  Nothing to do for now.  */
  1351.  
  1352. void
  1353. expand_end_try ()
  1354. {
  1355.   except_stack->data.except_stmt.after_label = gen_label_rtx ();
  1356.   expand_goto_internal (NULL, except_stack->data.except_stmt.after_label, 0);
  1357. }
  1358.  
  1359. /* Start an `except' nesting contour.
  1360.    EXITFLAG says whether this contour should be able to `exit' something.
  1361.    ESCAPEFLAG says whether this contour should be escapable.  */
  1362.  
  1363. void
  1364. expand_start_except (exitflag, escapeflag)
  1365.      int exitflag;
  1366.      int escapeflag;
  1367. {
  1368.   if (exitflag)
  1369.     {
  1370.       struct nesting *n;
  1371.       /* An `exit' from catch clauses goes out to next exit level,
  1372.      if there is one.  Otherwise, it just goes to the end
  1373.      of the construct.  */
  1374.       for (n = except_stack->next; n; n = n->next)
  1375.     if (n->exit_label != 0)
  1376.       {
  1377.         except_stack->exit_label = n->exit_label;
  1378.         break;
  1379.       }
  1380.       if (n == 0)
  1381.     except_stack->exit_label = except_stack->data.except_stmt.after_label;
  1382.     }
  1383.   if (escapeflag)
  1384.     {
  1385.       struct nesting *n;
  1386.       /* An `escape' from catch clauses goes out to next escape level,
  1387.      if there is one.  Otherwise, it just goes to the end
  1388.      of the construct.  */
  1389.       for (n = except_stack->next; n; n = n->next)
  1390.     if (n->data.except_stmt.escape_label != 0)
  1391.       {
  1392.         except_stack->data.except_stmt.escape_label
  1393.           = n->data.except_stmt.escape_label;
  1394.         break;
  1395.       }
  1396.       if (n == 0)
  1397.     except_stack->data.except_stmt.escape_label
  1398.       = except_stack->data.except_stmt.after_label;
  1399.     }
  1400.   do_pending_stack_adjust ();
  1401.   emit_label (except_stack->data.except_stmt.except_label);
  1402. }
  1403.  
  1404. /* Generate code to `escape' from an exception contour.  This
  1405.    is like `exiting', but does not conflict with constructs which
  1406.    use `exit_label'.
  1407.  
  1408.    Return nonzero if this contour is escapable, otherwise
  1409.    return zero, and language-specific code will emit the
  1410.    appropriate error message.  */
  1411. int
  1412. expand_escape_except ()
  1413. {
  1414.   struct nesting *n;
  1415.   last_expr_type = 0;
  1416.   for (n = except_stack; n; n = n->next)
  1417.     if (n->data.except_stmt.escape_label != 0)
  1418.       {
  1419.     expand_goto_internal (0, n->data.except_stmt.escape_label, 0);
  1420.     return 1;
  1421.       }
  1422.  
  1423.   return 0;
  1424. }
  1425.  
  1426. /* Finish processing and `except' contour.
  1427.    Culls out all exceptions which might be raise but not
  1428.    handled, and returns the list to the caller.
  1429.    Language-specific code is responsible for dealing with these
  1430.    exceptions.  */
  1431.  
  1432. tree
  1433. expand_end_except ()
  1434. {
  1435.   struct nesting *n;
  1436.   tree raised = NULL_TREE;
  1437.  
  1438.   do_pending_stack_adjust ();
  1439.   emit_label (except_stack->data.except_stmt.after_label);
  1440.  
  1441.   n = except_stack->next;
  1442.   if (n)
  1443.     {
  1444.       /* Propagate exceptions raised but not handled to next
  1445.      highest level.  */
  1446.       tree handled = except_stack->data.except_stmt.raised;
  1447.       if (handled != void_type_node)
  1448.     {
  1449.       tree prev = NULL_TREE;
  1450.       raised = except_stack->data.except_stmt.raised;
  1451.       while (handled)
  1452.         {
  1453.           tree this_raise;
  1454.           for (this_raise = raised, prev = 0; this_raise;
  1455.            this_raise = TREE_CHAIN (this_raise))
  1456.         {
  1457.           if (value_member (TREE_VALUE (this_raise), handled))
  1458.             {
  1459.               if (prev)
  1460.             TREE_CHAIN (prev) = TREE_CHAIN (this_raise);
  1461.               else
  1462.             {
  1463.               raised = TREE_CHAIN (raised);
  1464.               if (raised == NULL_TREE)
  1465.                 goto nada;
  1466.             }
  1467.             }
  1468.           else
  1469.             prev = this_raise;
  1470.         }
  1471.           handled = TREE_CHAIN (handled);
  1472.         }
  1473.       if (prev == NULL_TREE)
  1474.         prev = raised;
  1475.       if (prev)
  1476.         TREE_CHAIN (prev) = n->data.except_stmt.raised;
  1477.     nada:
  1478.       n->data.except_stmt.raised = raised;
  1479.     }
  1480.     }
  1481.  
  1482.   POPSTACK (except_stack);
  1483.   last_expr_type = 0;
  1484.   return raised;
  1485. }
  1486.  
  1487. /* Record that exception EX is caught by this exception handler.
  1488.    Return nonzero if in exception handling construct, otherwise return 0.  */
  1489.  
  1490. int
  1491. expand_catch (ex)
  1492.      tree ex;
  1493. {
  1494.   tree *raises_ptr;
  1495.  
  1496.   if (except_stack == 0)
  1497.     return 0;
  1498.   raises_ptr = &except_stack->data.except_stmt.handled;
  1499.   if (*raises_ptr != void_type_node
  1500.       && ex != NULL_TREE
  1501.       && ! value_member (ex, *raises_ptr))
  1502.     *raises_ptr = tree_cons (NULL_TREE, ex, *raises_ptr);
  1503.   return 1;
  1504. }
  1505.  
  1506. /* Record that this exception handler catches all exceptions.
  1507.    Return nonzero if in exception handling construct, otherwise return 0.  */
  1508.  
  1509. int
  1510. expand_catch_default ()
  1511. {
  1512.   if (except_stack == 0)
  1513.     return 0;
  1514.   except_stack->data.except_stmt.handled = void_type_node;
  1515.   return 1;
  1516. }
  1517.  
  1518. int
  1519. expand_end_catch ()
  1520. {
  1521.   if (except_stack == 0 || except_stack->data.except_stmt.after_label == 0)
  1522.     return 0;
  1523.   expand_goto_internal (0, except_stack->data.except_stmt.after_label, 0);
  1524.   return 1;
  1525. }
  1526.  
  1527. /* Generate RTL for the start of an if-then.  COND is the expression
  1528.    whose truth should be tested.
  1529.  
  1530.    If EXITFLAG is nonzero, this conditional is visible to
  1531.    `exit_something'.  */
  1532.  
  1533. void
  1534. expand_start_cond (cond, exitflag)
  1535.      tree cond;
  1536.      int exitflag;
  1537. {
  1538.   struct nesting *thiscond
  1539.     = (struct nesting *) obstack_alloc (&stmt_obstack, sizeof (struct nesting));
  1540.  
  1541.   /* Make an entry on cond_stack for the cond we are entering.  */
  1542.  
  1543.   thiscond->next = cond_stack;
  1544.   thiscond->all = nesting_stack;
  1545.   thiscond->depth = ++nesting_depth;
  1546.   thiscond->data.cond.after_label = 0;
  1547.   thiscond->data.cond.else_label = gen_label_rtx ();
  1548.   thiscond->exit_label = exitflag ? thiscond->data.cond.else_label : 0;
  1549.   cond_stack = thiscond;
  1550.   nesting_stack = thiscond;
  1551.  
  1552.   do_jump (cond, thiscond->data.cond.else_label, NULL);
  1553. }
  1554.  
  1555. /* Generate RTL for the end of an if-then with no else-clause.
  1556.    Pop the record for it off of cond_stack.  */
  1557.  
  1558. void
  1559. expand_end_cond ()
  1560. {
  1561.   struct nesting *thiscond = cond_stack;
  1562.  
  1563.   do_pending_stack_adjust ();
  1564.   emit_label (thiscond->data.cond.else_label);
  1565.  
  1566.   POPSTACK (cond_stack);
  1567.   last_expr_type = 0;
  1568. }
  1569.  
  1570. /* Generate RTL between the then-clause and the else-clause
  1571.    of an if-then-else.  */
  1572.  
  1573. void
  1574. expand_start_else ()
  1575. {
  1576.   cond_stack->data.cond.after_label = gen_label_rtx ();
  1577.   if (cond_stack->exit_label != 0)
  1578.     cond_stack->exit_label = cond_stack->data.cond.after_label;
  1579.   emit_jump (cond_stack->data.cond.after_label);
  1580.   if (cond_stack->data.cond.else_label)
  1581.     emit_label (cond_stack->data.cond.else_label);
  1582. }
  1583.  
  1584. /* Generate RTL for the end of an if-then-else.
  1585.    Pop the record for it off of cond_stack.  */
  1586.  
  1587. void
  1588. expand_end_else ()
  1589. {
  1590.   struct nesting *thiscond = cond_stack;
  1591.  
  1592.   do_pending_stack_adjust ();
  1593.   /* Note: a syntax error can cause this to be called
  1594.      without first calling `expand_start_else'.  */
  1595.   if (thiscond->data.cond.after_label)
  1596.     emit_label (thiscond->data.cond.after_label);
  1597.  
  1598.   POPSTACK (cond_stack);
  1599.   last_expr_type = 0;
  1600. }
  1601.  
  1602. /* Generate RTL for the start of a loop.  EXIT_FLAG is nonzero if this
  1603.    loop should be exited by `exit_something'.  This is a loop for which
  1604.    `expand_continue' will jump to the top of the loop.
  1605.  
  1606.    Make an entry on loop_stack to record the labels associated with
  1607.    this loop.  */
  1608.  
  1609. void
  1610. expand_start_loop (exit_flag)
  1611.      int exit_flag;
  1612. {
  1613.   register struct nesting *thisloop
  1614.     = (struct nesting *) obstack_alloc (&stmt_obstack, sizeof (struct nesting));
  1615.  
  1616.   /* Make an entry on loop_stack for the loop we are entering.  */
  1617.  
  1618.   thisloop->next = loop_stack;
  1619.   thisloop->all = nesting_stack;
  1620.   thisloop->depth = ++nesting_depth;
  1621.   thisloop->data.loop.start_label = gen_label_rtx ();
  1622.   thisloop->data.loop.end_label = gen_label_rtx ();
  1623.   thisloop->data.loop.continue_label = thisloop->data.loop.start_label;
  1624.   thisloop->exit_label = exit_flag ? thisloop->data.loop.end_label : 0;
  1625.   loop_stack = thisloop;
  1626.   nesting_stack = thisloop;
  1627.  
  1628.   do_pending_stack_adjust ();
  1629.   emit_queue ();
  1630.   emit_note (0, NOTE_INSN_LOOP_BEG);
  1631.   emit_label (thisloop->data.loop.start_label);
  1632. }
  1633.  
  1634. /* Like expand_start_loop but for a loop where the continuation point
  1635.    (for expand_continue_loop) will be specified explicitly.  */
  1636.  
  1637. void
  1638. expand_start_loop_continue_elsewhere (exit_flag)
  1639.      int exit_flag;
  1640. {
  1641.   expand_start_loop (exit_flag);
  1642.   loop_stack->data.loop.continue_label = gen_label_rtx ();
  1643. }
  1644.  
  1645. /* Specify the continuation point for a loop started with
  1646.    expand_start_loop_continue_elsewhere.
  1647.    Use this at the point in the code to which a continue statement
  1648.    should jump.  */
  1649.  
  1650. void
  1651. expand_loop_continue_here ()
  1652. {
  1653.   do_pending_stack_adjust ();
  1654.   emit_note (0, NOTE_INSN_LOOP_CONT);
  1655.   emit_label (loop_stack->data.loop.continue_label);
  1656. }
  1657.  
  1658. /* Finish a loop.  Generate a jump back to the top and the loop-exit label.
  1659.    Pop the block off of loop_stack.  */
  1660.  
  1661. void
  1662. expand_end_loop ()
  1663. {
  1664.   register rtx insn = get_last_insn ();
  1665.   register rtx start_label = loop_stack->data.loop.start_label;
  1666.  
  1667.   do_pending_stack_adjust ();
  1668.  
  1669.   /* If optimizing, perhaps reorder the loop.  If the loop
  1670.      starts with a conditional exit, roll that to the end
  1671.      where it will optimize together with the jump back.  */
  1672.   if (optimize
  1673.       &&
  1674.       ! (GET_CODE (insn) == JUMP_INSN
  1675.      && GET_CODE (PATTERN (insn)) == SET
  1676.      && SET_DEST (PATTERN (insn)) == pc_rtx
  1677.      && GET_CODE (SET_SRC (PATTERN (insn))) == IF_THEN_ELSE))
  1678.     {
  1679.       /* Scan insns from the top of the loop looking for a qualified
  1680.      conditional exit.  */
  1681.       for (insn = loop_stack->data.loop.start_label; insn; insn= NEXT_INSN (insn))
  1682.     if (GET_CODE (insn) == JUMP_INSN && GET_CODE (PATTERN (insn)) == SET
  1683.         && SET_DEST (PATTERN (insn)) == pc_rtx
  1684.         && GET_CODE (SET_SRC (PATTERN (insn))) == IF_THEN_ELSE
  1685.         &&
  1686.         ((GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 1)) == LABEL_REF
  1687.           && (XEXP (XEXP (SET_SRC (PATTERN (insn)), 1), 0)
  1688.           == loop_stack->data.loop.end_label))
  1689.          ||
  1690.          (GET_CODE (XEXP (SET_SRC (PATTERN (insn)), 2)) == LABEL_REF
  1691.           && (XEXP (XEXP (SET_SRC (PATTERN (insn)), 2), 0)
  1692.           == loop_stack->data.loop.end_label))))
  1693.       break;
  1694.       if (insn != 0)
  1695.     {
  1696.       /* We found one.  Move everything from there up
  1697.          to the end of the loop, and add a jump into the loop
  1698.          to jump to there.  */
  1699.       register rtx newstart_label = gen_label_rtx ();
  1700.  
  1701.       emit_label_after (newstart_label, PREV_INSN (start_label));
  1702.       reorder_insns (start_label, insn, get_last_insn ());
  1703.       emit_jump_insn_after (gen_jump (start_label), PREV_INSN (newstart_label));
  1704.       emit_barrier_after (PREV_INSN (newstart_label));
  1705.       start_label = newstart_label;
  1706.     }
  1707.     }
  1708.  
  1709.   emit_jump (start_label);
  1710.   emit_note (0, NOTE_INSN_LOOP_END);
  1711.   emit_label (loop_stack->data.loop.end_label);
  1712.  
  1713.   POPSTACK (loop_stack);
  1714.  
  1715.   last_expr_type = 0;
  1716. }
  1717.  
  1718. /* Generate a jump to the current loop's continue-point.
  1719.    This is usually the top of the loop, but may be specified
  1720.    explicitly elsewhere.  If not currently inside a loop,
  1721.    return 0 and do nothing; caller will print an error message.  */
  1722.  
  1723. int
  1724. expand_continue_loop ()
  1725. {
  1726.   last_expr_type = 0;
  1727.   if (loop_stack == 0)
  1728.     return 0;
  1729.   expand_goto_internal (0, loop_stack->data.loop.continue_label, 0);
  1730.   return 1;
  1731. }
  1732.  
  1733. /* Generate a jump to exit the current loop.  If not currently inside a loop,
  1734.    return 0 and do nothing; caller will print an error message.  */
  1735.  
  1736. int
  1737. expand_exit_loop ()
  1738. {
  1739.   last_expr_type = 0;
  1740.   if (loop_stack == 0)
  1741.     return 0;
  1742.   expand_goto_internal (0, loop_stack->data.loop.end_label, 0);
  1743.   return 1;
  1744. }
  1745.  
  1746. /* Generate a conditional jump to exit the current loop if COND
  1747.    evaluates to zero.  If not currently inside a loop,
  1748.    return 0 and do nothing; caller will print an error message.  */
  1749.  
  1750. int
  1751. expand_exit_loop_if_false (cond)
  1752.      tree cond;
  1753. {
  1754.   last_expr_type = 0;
  1755.   if (loop_stack == 0)
  1756.     return 0;
  1757.   do_jump (cond, loop_stack->data.loop.end_label, NULL);
  1758.   return 1;
  1759. }
  1760.  
  1761. /* Return non-zero if currently inside a loop.  */
  1762.  
  1763. int
  1764. inside_loop ()
  1765. {
  1766.   return loop_stack != 0;
  1767. }
  1768.  
  1769. /* Generate a jump to exit the current loop, conditional, binding contour
  1770.    or case statement.  Not all such constructs are visible to this function,
  1771.    only those started with EXIT_FLAG nonzero.  Individual languages use
  1772.    the EXIT_FLAG parameter to control which kinds of constructs you can
  1773.    exit this way.
  1774.  
  1775.    If not currently inside anything that can be exited,
  1776.    return 0 and do nothing; caller will print an error message.  */
  1777.  
  1778. int
  1779. expand_exit_something ()
  1780. {
  1781.   struct nesting *n;
  1782.   last_expr_type = 0;
  1783.   for (n = nesting_stack; n; n = n->all)
  1784.     if (n->exit_label != 0)
  1785.       {
  1786.     expand_goto_internal (0, n->exit_label, 0);
  1787.     return 1;
  1788.       }
  1789.  
  1790.   return 0;
  1791. }
  1792.  
  1793. /* Generate RTL to return from the current function, with no value.
  1794.    (That is, we do not do anything about returning any value.)  */
  1795.  
  1796. void
  1797. expand_null_return ()
  1798. {
  1799.   struct nesting *block = block_stack;
  1800.   rtx last_insn = 0;
  1801.  
  1802.   /* Does any pending block have cleanups?  */
  1803.  
  1804.   while (block && block->data.block.cleanups == 0)
  1805.     block = block->next;
  1806.  
  1807.   /* If yes, use a goto to return, since that runs cleanups.  */
  1808.  
  1809.   expand_null_return_1 (last_insn, block != 0);
  1810. }
  1811.  
  1812. /* Output a return with no value.  If LAST_INSN is nonzero,
  1813.    pretend that the return takes place after LAST_INSN.
  1814.    If USE_GOTO is nonzero then don't use a return instruction;
  1815.    go to the return label instead.  This causes any cleanups
  1816.    of pending blocks to be executed normally.  */
  1817.  
  1818. static void
  1819. expand_null_return_1 (last_insn, use_goto)
  1820.      rtx last_insn;
  1821.      int use_goto;
  1822. {
  1823.   rtx end_label = cleanup_label ? cleanup_label : return_label;
  1824.  
  1825.   clear_pending_stack_adjust ();
  1826.   do_pending_stack_adjust ();
  1827.   last_expr_type = 0;
  1828.  
  1829.   /* PCC-struct return always uses an epilogue.  */
  1830.   if (current_function_returns_pcc_struct || use_goto)
  1831.     {
  1832.       if (end_label == 0)
  1833.     end_label = return_label = gen_label_rtx ();
  1834.       expand_goto_internal (0, end_label, last_insn);
  1835.       return;
  1836.     }
  1837.  
  1838.   /* Otherwise output a simple return-insn if one is available,
  1839.      unless it won't do the job.  */
  1840. #ifdef HAVE_return
  1841.   if (HAVE_return && use_goto == 0 && cleanup_label == 0)
  1842.     {
  1843.       emit_jump_insn (gen_return ());
  1844.       emit_barrier ();
  1845.       return;
  1846.     }
  1847. #endif
  1848.  
  1849.   /* Otherwise jump to the epilogue.  */
  1850.   expand_goto_internal (0, end_label, last_insn);
  1851. }
  1852.  
  1853. /* Generate RTL to evaluate the expression RETVAL and return it
  1854.    from the current function.  */
  1855.  
  1856. void
  1857. expand_return (retval)
  1858.      tree retval;
  1859. {
  1860.   /* If there are any cleanups to be performed, then they will
  1861.      be inserted following LAST_INSN.  It is desirable
  1862.      that the last_insn, for such purposes, should be the
  1863.      last insn before computing the return value.  Otherwise, cleanups
  1864.      which call functions can clobber the return value.  */
  1865.   /* ??? rms: I think that is erroneous, because in C++ it would
  1866.      run destructors on variables that might be used in the subsequent
  1867.      computation of the return value.  */
  1868.   rtx last_insn = 0;
  1869.   register rtx val = 0;
  1870.   register rtx op0;
  1871.   tree retval_rhs;
  1872.   int cleanups;
  1873.   struct nesting *block;
  1874.  
  1875.   /* Are any cleanups needed?  E.g. C++ destructors to be run?  */
  1876.   cleanups = any_pending_cleanups (1);
  1877.  
  1878.   if (TREE_CODE (retval) == RESULT_DECL)
  1879.     retval_rhs = retval;
  1880.   else if ((TREE_CODE (retval) == MODIFY_EXPR || TREE_CODE (retval) == INIT_EXPR)
  1881.        && TREE_CODE (TREE_OPERAND (retval, 0)) == RESULT_DECL)
  1882.     retval_rhs = TREE_OPERAND (retval, 1);
  1883.   else if (TREE_TYPE (retval) == void_type_node)
  1884.     /* Recognize tail-recursive call to void function.  */
  1885.     retval_rhs = retval;
  1886.   else
  1887.     retval_rhs = NULL_TREE;
  1888.  
  1889.   /* Only use `last_insn' if there are cleanups which must be run.  */
  1890.   if (cleanups || cleanup_label != 0)
  1891.     last_insn = get_last_insn ();
  1892.  
  1893.   /* Distribute return down conditional expr if either of the sides
  1894.      may involve tail recursion (see test below).  This enhances the number
  1895.      of tail recursions we see.  Don't do this always since it can produce
  1896.      sub-optimal code in some cases and we distribute assignments into
  1897.      conditional expressions when it would help.  */
  1898.      
  1899.   if (optimize && retval_rhs != 0
  1900.       && frame_offset == 0
  1901.       && TREE_CODE (retval_rhs) == COND_EXPR
  1902.       && (TREE_CODE (TREE_OPERAND (retval_rhs, 1)) == CALL_EXPR
  1903.       || TREE_CODE (TREE_OPERAND (retval_rhs, 2)) == CALL_EXPR))
  1904.     {
  1905.       rtx label = gen_label_rtx ();
  1906.       do_jump (TREE_OPERAND (retval_rhs, 0), label, 0);
  1907.       expand_return (build (MODIFY_EXPR, TREE_TYPE (current_function_decl),
  1908.                 DECL_RESULT (current_function_decl),
  1909.                 TREE_OPERAND (retval_rhs, 1)));
  1910.       emit_label (label);
  1911.       expand_return (build (MODIFY_EXPR, TREE_TYPE (current_function_decl),
  1912.                 DECL_RESULT (current_function_decl),
  1913.                 TREE_OPERAND (retval_rhs, 2)));
  1914.       return;
  1915.     }
  1916.  
  1917.   /* For tail-recursive call to current function,
  1918.      just jump back to the beginning.
  1919.      It's unsafe if any auto variable in this function
  1920.      has its address taken; for simplicity,
  1921.      require stack frame to be empty.  */
  1922.   if (optimize && retval_rhs != 0
  1923.       && frame_offset == STARTING_FRAME_OFFSET
  1924.       && TREE_CODE (retval_rhs) == CALL_EXPR
  1925.       && TREE_CODE (TREE_OPERAND (retval_rhs, 0)) == ADDR_EXPR
  1926.       && TREE_OPERAND (TREE_OPERAND (retval_rhs, 0), 0) == current_function_decl
  1927.       /* Finish checking validity, and if valid emit code
  1928.      to set the argument variables for the new call.  */
  1929.       && tail_recursion_args (TREE_OPERAND (retval_rhs, 1),
  1930.                   DECL_ARGUMENTS (current_function_decl)))
  1931.     {
  1932.       if (tail_recursion_label == 0)
  1933.     {
  1934.       tail_recursion_label = gen_label_rtx ();
  1935.       emit_label_after (tail_recursion_label,
  1936.                 tail_recursion_reentry);
  1937.     }
  1938.       expand_goto_internal (0, tail_recursion_label, last_insn);
  1939.       emit_barrier ();
  1940.       return;
  1941.     }
  1942. #ifdef HAVE_return
  1943.   /* This optimization is safe if there are local cleanups
  1944.      because expand_null_return takes care of them.
  1945.      ??? I think it should also be safe when there is a cleanup label,
  1946.      because expand_null_return takes care of them, too.
  1947.      Any reason why not?  */
  1948.   if (HAVE_return && cleanup_label == 0
  1949.       && ! current_function_returns_pcc_struct)
  1950.     {
  1951.       /* If this is  return x == y;  then generate
  1952.      if (x == y) return 1; else return 0;
  1953.      if we can do it with explicit return insns.  */
  1954.       if (retval_rhs)
  1955.     switch (TREE_CODE (retval_rhs))
  1956.       {
  1957.       case EQ_EXPR:
  1958.       case NE_EXPR:
  1959.       case GT_EXPR:
  1960.       case GE_EXPR:
  1961.       case LT_EXPR:
  1962.       case LE_EXPR:
  1963.       case TRUTH_ANDIF_EXPR:
  1964.       case TRUTH_ORIF_EXPR:
  1965.       case TRUTH_AND_EXPR:
  1966.       case TRUTH_OR_EXPR:
  1967.       case TRUTH_NOT_EXPR:
  1968.         op0 = gen_label_rtx ();
  1969.         val = DECL_RTL (DECL_RESULT (current_function_decl));
  1970.         jumpifnot (retval_rhs, op0);
  1971.         emit_move_insn (val, const1_rtx);
  1972.         emit_insn (gen_rtx (USE, VOIDmode, val));
  1973.         expand_null_return ();
  1974.         emit_label (op0);
  1975.         emit_move_insn (val, const0_rtx);
  1976.         emit_insn (gen_rtx (USE, VOIDmode, val));
  1977.         expand_null_return ();
  1978.         return;
  1979.       }
  1980.     }
  1981. #endif /* HAVE_return */
  1982.  
  1983.   if (cleanups
  1984.       && retval_rhs != 0
  1985.       && TREE_TYPE (retval_rhs) != void_type_node
  1986.       && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG)
  1987.     {
  1988.       /* Calculate the return value into a pseudo reg.  */
  1989.       val = expand_expr (retval_rhs, 0, VOIDmode, 0);
  1990.       emit_queue ();
  1991.       /* Put the cleanups here.  */
  1992.       last_insn = get_last_insn ();
  1993.       /* Copy the value into hard return reg.  */
  1994.       emit_move_insn (DECL_RTL (DECL_RESULT (current_function_decl)), val);
  1995.       val = DECL_RTL (DECL_RESULT (current_function_decl));
  1996.  
  1997.       if (GET_CODE (val) == REG && REGNO (val) < FIRST_PSEUDO_REGISTER)
  1998.     emit_insn (gen_rtx (USE, VOIDmode, val));
  1999.       expand_null_return_1 (last_insn, cleanups);
  2000.     }
  2001.   else
  2002.     {
  2003.       /* No cleanups or no hard reg used;
  2004.      calculate value into hard return reg
  2005.      and let cleanups come after.  */
  2006.       expand_expr (retval, 0, VOIDmode, 0);
  2007.       emit_queue ();
  2008.  
  2009.       val = DECL_RTL (DECL_RESULT (current_function_decl));
  2010.       if (val && GET_CODE (val) == REG
  2011.       && REGNO (val) < FIRST_PSEUDO_REGISTER)
  2012.     emit_insn (gen_rtx (USE, VOIDmode, val));
  2013.       expand_null_return ();
  2014.     }
  2015. }
  2016.  
  2017. /* Return 1 if the end of the generated RTX is not a barrier.
  2018.    This means code already compiled can drop through.  */
  2019.  
  2020. int
  2021. drop_through_at_end_p ()
  2022. {
  2023.   rtx insn = get_last_insn ();
  2024.   while (insn && GET_CODE (insn) == NOTE)
  2025.     insn = PREV_INSN (insn);
  2026.   return insn && GET_CODE (insn) != BARRIER;
  2027. }
  2028.  
  2029. /* Emit code to alter this function's formal parms for a tail-recursive call.
  2030.    ACTUALS is a list of actual parameter expressions (chain of TREE_LISTs).
  2031.    FORMALS is the chain of decls of formals.
  2032.    Return 1 if this can be done;
  2033.    otherwise return 0 and do not emit any code.  */
  2034.  
  2035. static int
  2036. tail_recursion_args (actuals, formals)
  2037.      tree actuals, formals;
  2038. {
  2039.   register tree a = actuals, f = formals;
  2040.   register int i;
  2041.   register rtx *argvec;
  2042.  
  2043.   /* Check that number and types of actuals are compatible
  2044.      with the formals.  This is not always true in valid C code.
  2045.      Also check that no formal needs to be addressable
  2046.      and that all formals are scalars.  */
  2047.  
  2048.   /* Also count the args.  */
  2049.  
  2050.   for (a = actuals, f = formals, i = 0; a && f; a = TREE_CHAIN (a), f = TREE_CHAIN (f), i++)
  2051.     {
  2052.       if (TREE_TYPE (TREE_VALUE (a)) != TREE_TYPE (f))
  2053.     return 0;
  2054.       if (GET_CODE (DECL_RTL (f)) != REG || DECL_MODE (f) == BLKmode)
  2055.     return 0;
  2056.     }
  2057.   if (a != 0 || f != 0)
  2058.     return 0;
  2059.  
  2060.   /* Compute all the actuals.  */
  2061.  
  2062.   argvec = (rtx *) alloca (i * sizeof (rtx));
  2063.  
  2064.   for (a = actuals, i = 0; a; a = TREE_CHAIN (a), i++)
  2065.     argvec[i] = expand_expr (TREE_VALUE (a), 0, VOIDmode, 0);
  2066.  
  2067.   /* Find which actual values refer to current values of previous formals.
  2068.      Copy each of them now, before any formal is changed.  */
  2069.  
  2070.   for (a = actuals, i = 0; a; a = TREE_CHAIN (a), i++)
  2071.     {
  2072.       int copy = 0;
  2073.       register int j;
  2074.       for (f = formals, j = 0; j < i; f = TREE_CHAIN (f), j++)
  2075.     if (reg_mentioned_p (DECL_RTL (f), argvec[i]))
  2076.       { copy = 1; break; }
  2077.       if (copy)
  2078.     argvec[i] = copy_to_reg (argvec[i]);
  2079.     }
  2080.  
  2081.   /* Store the values of the actuals into the formals.  */
  2082.  
  2083.   for (f = formals, a = actuals, i = 0; f;
  2084.        f = TREE_CHAIN (f), a = TREE_CHAIN (a), i++)
  2085.     {
  2086.       if (DECL_MODE (f) == GET_MODE (argvec[i]))
  2087.     emit_move_insn (DECL_RTL (f), argvec[i]);
  2088.       else
  2089.     convert_move (DECL_RTL (f), argvec[i],
  2090.               TREE_UNSIGNED (TREE_TYPE (TREE_VALUE (a))));
  2091.     }
  2092.  
  2093.   return 1;
  2094. }
  2095.  
  2096. /* Generate the RTL code for entering a binding contour.
  2097.    The variables are declared one by one, by calls to `expand_decl'.
  2098.  
  2099.    EXIT_FLAG is nonzero if this construct should be visible to
  2100.    `exit_something'.  */
  2101.  
  2102. void
  2103. expand_start_bindings (exit_flag)
  2104.      int exit_flag;
  2105. {
  2106.   struct nesting *thisblock
  2107.     = (struct nesting *) obstack_alloc (&stmt_obstack, sizeof (struct nesting));
  2108.  
  2109.   rtx note = emit_note (0, NOTE_INSN_BLOCK_BEG);
  2110.  
  2111.   /* Make an entry on block_stack for the block we are entering.  */
  2112.  
  2113.   thisblock->next = block_stack;
  2114.   thisblock->all = nesting_stack;
  2115.   thisblock->depth = ++nesting_depth;
  2116.   thisblock->data.block.stack_level = 0;
  2117.   thisblock->data.block.cleanups = 0;
  2118. #if 0
  2119.   if (block_stack)
  2120.     {
  2121.       if (block_stack->data.block.cleanups == NULL_TREE
  2122.       && (block_stack->data.block.outer_cleanups == NULL_TREE
  2123.           || block_stack->data.block.outer_cleanups == empty_cleanup_list))
  2124.     thisblock->data.block.outer_cleanups = empty_cleanup_list;
  2125.       else
  2126.     thisblock->data.block.outer_cleanups
  2127.       = tree_cons (NULL_TREE, block_stack->data.block.cleanups,
  2128.                block_stack->data.block.outer_cleanups);
  2129.     }
  2130.   else
  2131.     thisblock->data.block.outer_cleanups = 0;
  2132. #endif
  2133. #if 1
  2134.   if (block_stack
  2135.       && !(block_stack->data.block.cleanups == NULL_TREE
  2136.        && block_stack->data.block.outer_cleanups == NULL_TREE))
  2137.     thisblock->data.block.outer_cleanups
  2138.       = tree_cons (NULL_TREE, block_stack->data.block.cleanups,
  2139.            block_stack->data.block.outer_cleanups);
  2140.   else
  2141.     thisblock->data.block.outer_cleanups = 0;
  2142. #endif
  2143.   thisblock->data.block.label_chain = 0;
  2144.   thisblock->data.block.innermost_stack_block = stack_block_stack;
  2145.   thisblock->data.block.first_insn = note;
  2146.   thisblock->data.block.block_start_count = ++block_start_count;
  2147.   thisblock->exit_label = exit_flag ? gen_label_rtx () : 0;
  2148.   block_stack = thisblock;
  2149.   nesting_stack = thisblock;
  2150. }
  2151.  
  2152. /* Output a USE for any register use in RTL.
  2153.    This is used with -noreg to mark the extent of lifespan
  2154.    of any registers used in a user-visible variable's DECL_RTL.  */
  2155.  
  2156. void
  2157. use_variable (rtl)
  2158.      rtx rtl;
  2159. {
  2160.   if (GET_CODE (rtl) == REG)
  2161.     /* This is a register variable.  */
  2162.     emit_insn (gen_rtx (USE, VOIDmode, rtl));
  2163.   else if (GET_CODE (rtl) == MEM
  2164.        && GET_CODE (XEXP (rtl, 0)) == REG
  2165.        && XEXP (rtl, 0) != frame_pointer_rtx
  2166.        && XEXP (rtl, 0) != arg_pointer_rtx)
  2167.     /* This is a variable-sized structure.  */
  2168.     emit_insn (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)));
  2169. }
  2170.  
  2171. /* Like use_variable except that it outputs the USEs after INSN
  2172.    instead of at the end of the insn-chain.  */
  2173.  
  2174. static void
  2175. use_variable_after (rtl, insn)
  2176.      rtx rtl, insn;
  2177. {
  2178.   if (GET_CODE (rtl) == REG)
  2179.     /* This is a register variable.  */
  2180.     emit_insn_after (gen_rtx (USE, VOIDmode, rtl), insn);
  2181.   else if (GET_CODE (rtl) == MEM
  2182.        && GET_CODE (XEXP (rtl, 0)) == REG
  2183.        && XEXP (rtl, 0) != frame_pointer_rtx
  2184.        && XEXP (rtl, 0) != arg_pointer_rtx)
  2185.     /* This is a variable-sized structure.  */
  2186.     emit_insn_after (gen_rtx (USE, VOIDmode, XEXP (rtl, 0)), insn);
  2187. }
  2188.  
  2189. /* Generate RTL code to terminate a binding contour.
  2190.    VARS is the chain of VAR_DECL nodes
  2191.    for the variables bound in this contour.
  2192.    MARK_ENDS is nonzero if we should put a note at the beginning
  2193.    and end of this binding contour.
  2194.  
  2195.    DONT_JUMP_IN is nonzero if it is not valid to jump into this contour.
  2196.    (That is true automatically if the contour has a saved stack level.)  */
  2197.  
  2198. void
  2199. expand_end_bindings (vars, mark_ends, dont_jump_in)
  2200.      tree vars;
  2201.      int mark_ends;
  2202.      int dont_jump_in;
  2203. {
  2204.   register struct nesting *thisblock = block_stack;
  2205.   register tree decl;
  2206.  
  2207.   if (warn_unused)
  2208.     for (decl = vars; decl; decl = TREE_CHAIN (decl))
  2209.       if (! TREE_USED (decl) && TREE_CODE (decl) == VAR_DECL)
  2210.     warning_with_decl (decl, "unused variable `%s'");
  2211.  
  2212.   /* Mark the beginning and end of the scope if requested.  */
  2213.  
  2214.   if (mark_ends)
  2215.     emit_note (0, NOTE_INSN_BLOCK_END);
  2216.   else
  2217.     /* Get rid of the beginning-mark if we don't make an end-mark.  */
  2218.     NOTE_LINE_NUMBER (thisblock->data.block.first_insn) = NOTE_INSN_DELETED;
  2219.  
  2220.   if (thisblock->exit_label)
  2221.     {
  2222.       do_pending_stack_adjust ();
  2223.       emit_label (thisblock->exit_label);
  2224.     }
  2225.  
  2226.   /* Don't allow jumping into a block that has cleanups or a stack level.  */
  2227.   if (dont_jump_in
  2228.       || thisblock->data.block.stack_level != 0
  2229.       || thisblock->data.block.cleanups != 0)
  2230.     {
  2231.       struct label_chain *chain;
  2232.  
  2233.       /* Any labels in this block are no longer valid to go to.
  2234.      Mark them to cause an error message.  */
  2235.       for (chain = thisblock->data.block.label_chain; chain; chain = chain->next)
  2236.     {
  2237.       TREE_PACKED (chain->label) = 1;
  2238.       /* If any goto without a fixup came to this label,
  2239.          that must be an error, because gotos without fixups
  2240.          come from outside all saved stack-levels and all cleanups.  */
  2241.       if (TREE_ADDRESSABLE (chain->label))
  2242.         error_with_decl (chain->label,
  2243.                  "label `%s' used before containing binding contour");
  2244.     }
  2245.     }
  2246.  
  2247.   /* Restore stack level in effect before the block
  2248.      (only if variable-size objects allocated).  */
  2249.   /* Perform any cleanups associated with the block.  */
  2250.  
  2251.   if (thisblock->data.block.stack_level != 0
  2252.       || thisblock->data.block.cleanups != 0)
  2253.     {
  2254.       /* Don't let cleanups affect ({...}) constructs.  */
  2255.       int old_expr_stmts_for_value = expr_stmts_for_value;
  2256.       rtx old_last_expr_value = last_expr_value;
  2257.       tree old_last_expr_type = last_expr_type;
  2258.       expr_stmts_for_value = 0;
  2259.  
  2260.       /* Do the cleanups.  */
  2261.       expand_cleanups (thisblock->data.block.cleanups, 0);
  2262.       do_pending_stack_adjust ();
  2263.  
  2264.       expr_stmts_for_value = old_expr_stmts_for_value;
  2265.       last_expr_value = old_last_expr_value;
  2266.       last_expr_type = old_last_expr_type;
  2267.  
  2268.       /* Restore the stack level.  */
  2269.  
  2270.       if (thisblock->data.block.stack_level != 0)
  2271.     emit_move_insn (stack_pointer_rtx,
  2272.             thisblock->data.block.stack_level);
  2273.  
  2274.       /* Any gotos out of this block must also do these things.
  2275.      Also report any gotos with fixups that came to labels in this level.  */
  2276.       fixup_gotos (thisblock,
  2277.            thisblock->data.block.stack_level,
  2278.            thisblock->data.block.cleanups,
  2279.            thisblock->data.block.first_insn,
  2280.            dont_jump_in);
  2281.     }
  2282.  
  2283.   /* If doing stupid register allocation, make sure lives of all
  2284.      register variables declared here extend thru end of scope.  */
  2285.  
  2286.   if (obey_regdecls)
  2287.     for (decl = vars; decl; decl = TREE_CHAIN (decl))
  2288.       {
  2289.     rtx rtl = DECL_RTL (decl);
  2290.     if (TREE_CODE (decl) == VAR_DECL && rtl != 0)
  2291.       use_variable (rtl);
  2292.       }
  2293.  
  2294.   /* Restore block_stack level for containing block.  */
  2295.  
  2296.   stack_block_stack = thisblock->data.block.innermost_stack_block;
  2297.   POPSTACK (block_stack);
  2298. }
  2299.  
  2300. /* Generate RTL for the automatic variable declaration DECL.
  2301.    (Other kinds of declarations are simply ignored if seen here.)
  2302.    There is no special support here for C++ constructors.
  2303.    They should be handled by the proper code in DECL_INITIAL.  */
  2304.  
  2305. void
  2306. expand_decl (decl)
  2307.      register tree decl;
  2308. {
  2309.   struct nesting *thisblock = block_stack;
  2310.   tree type = TREE_TYPE (decl);
  2311.  
  2312.   /* Only automatic variables need any expansion done.
  2313.      Static and external variables, and external functions,
  2314.      will be handled by `assemble_variable' (called from finish_decl).
  2315.      TYPE_DECL and CONST_DECL require nothing.
  2316.      PARM_DECLs are handled in `assign_parms'.  */
  2317.  
  2318.   if (TREE_CODE (decl) != VAR_DECL)
  2319.     return;
  2320.   if (TREE_STATIC (decl) || TREE_EXTERNAL (decl))
  2321.     return;
  2322.  
  2323.   /* Create the RTL representation for the variable.  */
  2324.  
  2325.   if (type == error_mark_node)
  2326.     DECL_RTL (decl) = gen_rtx (MEM, BLKmode, const0_rtx);
  2327.   else if (DECL_SIZE (decl) == 0)
  2328.     /* Variable with incomplete type.  */
  2329.     {
  2330.       if (DECL_INITIAL (decl) == 0)
  2331.     /* Error message was already done; now avoid a crash.  */
  2332.     DECL_RTL (decl) = assign_stack_local (DECL_MODE (decl), 0);
  2333.       else
  2334.     /* An initializer is going to decide the size of this array.
  2335.        Until we know the size, represent its address with a reg.  */
  2336.     DECL_RTL (decl) = gen_rtx (MEM, BLKmode, gen_reg_rtx (Pmode));
  2337.     }
  2338.   else if (DECL_MODE (decl) != BLKmode
  2339.        /* If -ffloat-store, don't put explicit float vars
  2340.           into regs.  */
  2341.        && !(flag_float_store
  2342.         && TREE_CODE (type) == REAL_TYPE)
  2343.        && ! TREE_VOLATILE (decl)
  2344.        && ! TREE_ADDRESSABLE (decl)
  2345.        && (TREE_REGDECL (decl) || ! obey_regdecls))
  2346.     {
  2347.       /* Automatic variable that can go in a register.  */
  2348.       DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
  2349.       if (TREE_CODE (type) == POINTER_TYPE)
  2350.     mark_reg_pointer (DECL_RTL (decl));
  2351.       REG_USERVAR_P (DECL_RTL (decl)) = 1;
  2352.     }
  2353.   else if (TREE_LITERAL (DECL_SIZE (decl)))
  2354.     {
  2355.       rtx oldaddr = 0;
  2356.       rtx addr;
  2357.  
  2358.       /* If we previously made RTL for this decl, it must be an array
  2359.      whose size was determined by the initializer.
  2360.      The old address was a register; set that register now
  2361.      to the proper address.  */
  2362.       if (DECL_RTL (decl) != 0)
  2363.     {
  2364.       if (GET_CODE (DECL_RTL (decl)) != MEM
  2365.           || GET_CODE (XEXP (DECL_RTL (decl), 0)) != REG)
  2366.         abort ();
  2367.       oldaddr = XEXP (DECL_RTL (decl), 0);
  2368.     }
  2369.  
  2370.       /* Variable of fixed size that goes on the stack.  */
  2371.       DECL_RTL (decl)
  2372.     = assign_stack_local (DECL_MODE (decl),
  2373.                   (TREE_INT_CST_LOW (DECL_SIZE (decl))
  2374.                    * DECL_SIZE_UNIT (decl)
  2375.                    + BITS_PER_UNIT - 1)
  2376.                   / BITS_PER_UNIT);
  2377.       if (oldaddr)
  2378.     {
  2379.       addr = force_operand (XEXP (DECL_RTL (decl), 0), oldaddr);
  2380.       emit_move_insn (oldaddr, addr);
  2381.     }
  2382.  
  2383.       /* If this is a memory ref that contains aggregate components,
  2384.      mark it as such for cse and loop optimize.  */
  2385.       MEM_IN_STRUCT_P (DECL_RTL (decl))
  2386.     = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  2387.        || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
  2388.        || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE);
  2389. #if 0
  2390.       /* If this is in memory because of -ffloat-store,
  2391.      set the volatile bit, to prevent optimizations from
  2392.      undoing the effects.  */
  2393.       if (flag_float_store && TREE_CODE (type) == REAL_TYPE)
  2394.     MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
  2395. #endif
  2396.     }
  2397.   else
  2398.     /* Dynamic-size object: must push space on the stack.  */
  2399.     {
  2400.       rtx address, size;
  2401.  
  2402.       frame_pointer_needed = 1;
  2403.  
  2404.       /* Record the stack pointer on entry to block, if have
  2405.      not already done so.  */
  2406.       if (thisblock->data.block.stack_level == 0)
  2407.     {
  2408.       do_pending_stack_adjust ();
  2409.       thisblock->data.block.stack_level
  2410.         = copy_to_reg (stack_pointer_rtx);
  2411.       stack_block_stack = thisblock;
  2412.     }
  2413.  
  2414.       /* Compute the variable's size, in bytes.  */
  2415.       size = expand_expr (convert_units (DECL_SIZE (decl),
  2416.                      DECL_SIZE_UNIT (decl),
  2417.                      BITS_PER_UNIT),
  2418.               0, VOIDmode, 0);
  2419.  
  2420.       /* Round it up to this machine's required stack boundary.  */
  2421. #ifdef STACK_BOUNDARY
  2422.       /* Avoid extra code if we can prove it's a multiple already.  */
  2423.       if (DECL_SIZE_UNIT (decl) % STACK_BOUNDARY)
  2424.     {
  2425. #ifdef STACK_POINTER_OFFSET
  2426.       /* Avoid extra code if we can prove that adding STACK_POINTER_OFFSET
  2427.          will not give this address invalid alignment.  */
  2428.       if (DECL_ALIGN (decl) > ((STACK_POINTER_OFFSET * BITS_PER_UNIT) % STACK_BOUNDARY))
  2429.         size = plus_constant (size,
  2430.                   STACK_POINTER_OFFSET % (STACK_BOUNDARY / BITS_PER_UNIT));
  2431. #endif
  2432.       size = round_push (size);
  2433.     }
  2434. #endif /* STACK_BOUNDARY */
  2435.  
  2436.       /* Make space on the stack, and get an rtx for the address of it.  */
  2437. #ifdef STACK_GROWS_DOWNWARD
  2438.       anti_adjust_stack (size);
  2439. #endif
  2440.       address = copy_to_reg (stack_pointer_rtx);
  2441. #ifdef STACK_POINTER_OFFSET
  2442.       {
  2443.     /* If the contents of the stack pointer reg are offset from the
  2444.        actual top-of-stack address, add the offset here.  */
  2445.     rtx sp_offset = gen_rtx (CONST_INT, VOIDmode, STACK_POINTER_OFFSET);
  2446. #ifdef STACK_BOUNDARY
  2447. #ifdef STACK_GROWS_DOWNWARD
  2448.     int direction = 1;
  2449. #else /* not STACK_GROWS_DOWNWARD */
  2450.     int direction = 0;
  2451. #endif /* not STACK_GROWS_DOWNWARD */
  2452.     if (DECL_ALIGN (decl) > ((STACK_POINTER_OFFSET * BITS_PER_UNIT) % STACK_BOUNDARY))
  2453.       sp_offset = plus_constant (sp_offset,
  2454.                      (STACK_POINTER_OFFSET
  2455.                       % (STACK_BOUNDARY / BITS_PER_UNIT)
  2456.                       * direction));
  2457. #endif /* STACK_BOUNDARY */
  2458.     emit_insn (gen_add2_insn (address, sp_offset));
  2459.       }
  2460. #endif /* STACK_POINTER_OFFSET */
  2461. #ifndef STACK_GROWS_DOWNWARD
  2462.       anti_adjust_stack (size);
  2463. #endif
  2464.  
  2465.       /* Some systems require a particular insn to refer to the stack
  2466.      to make the pages exist.  */
  2467. #ifdef HAVE_probe
  2468.       if (HAVE_probe)
  2469.     emit_insn (gen_probe ());
  2470. #endif
  2471.  
  2472.       /* Reference the variable indirect through that rtx.  */
  2473.       DECL_RTL (decl) = gen_rtx (MEM, DECL_MODE (decl), address);
  2474.     }
  2475.  
  2476.   if (TREE_VOLATILE (decl))
  2477.     MEM_VOLATILE_P (DECL_RTL (decl)) = 1;
  2478.   if (TREE_READONLY (decl))
  2479.     RTX_UNCHANGING_P (DECL_RTL (decl)) = 1;
  2480.  
  2481.   /* If doing stupid register allocation, make sure life of any
  2482.      register variable starts here, at the start of its scope.  */
  2483.  
  2484.   if (obey_regdecls)
  2485.     use_variable (DECL_RTL (decl));
  2486. }
  2487.  
  2488. /* Emit code to perform the initialization of a declaration DECL.  */
  2489.  
  2490. void
  2491. expand_decl_init (decl)
  2492.      tree decl;
  2493. {
  2494.   if (TREE_STATIC (decl))
  2495.     return;
  2496.  
  2497.   /* Compute and store the initial value now.  */
  2498.  
  2499.   if (DECL_INITIAL (decl) == error_mark_node)
  2500.     {
  2501.       enum tree_code code = TREE_CODE (TREE_TYPE (decl));
  2502.       if (code == INTEGER_TYPE || code == REAL_TYPE || code == ENUMERAL_TYPE
  2503.       || code == POINTER_TYPE)
  2504.     expand_assignment (decl, convert (TREE_TYPE (decl), integer_zero_node),
  2505.                0, 0);
  2506.       emit_queue ();
  2507.     }
  2508.   else if (DECL_INITIAL (decl) && TREE_CODE (DECL_INITIAL (decl)) != TREE_LIST)
  2509.     {
  2510.       emit_line_note (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl));
  2511.       expand_assignment (decl, DECL_INITIAL (decl), 0, 0);
  2512.       emit_queue ();
  2513.     }
  2514. }
  2515.  
  2516. /* CLEANUP is an expression to be executed at exit from this binding contour;
  2517.    for example, in C++, it might call the destructor for this variable.
  2518.  
  2519.    If CLEANUP contains any SAVE_EXPRs, then you must preevaluate them
  2520.    either before or after calling `expand_decl' but before compiling
  2521.    any subsequent expressions.  This is because CLEANUP may be expanded
  2522.    more than once, on different branches of execution.
  2523.    For the same reason, CLEANUP may not contain a CALL_EXPR
  2524.    except as its topmost node--else `preexpand_calls' would get confused.
  2525.  
  2526.    If CLEANUP is nonzero and DECL is zero, we record a cleanup
  2527.    that is not associated with any particular variable.
  2528.  
  2529.    Return 0 if such an expansion is invalid.  Otherwise, return 1.  */
  2530. int
  2531. expand_decl_cleanup (decl, cleanup)
  2532.      tree decl, cleanup;
  2533. {
  2534.   struct nesting *thisblock = block_stack;
  2535.  
  2536.   /* Error if we are not in any block.  */
  2537.   if (thisblock == 0)
  2538.     return 0;
  2539.  
  2540.   /* Record the cleanup if there is one.  */
  2541.  
  2542.   if (cleanup != 0)
  2543.     {
  2544.       thisblock->data.block.cleanups
  2545.     = temp_tree_cons (decl, cleanup, thisblock->data.block.cleanups);
  2546.       /* If this block has a cleanup, it belongs in stack_block_stack.  */
  2547.       stack_block_stack = thisblock;
  2548.     }
  2549.   return 1;
  2550. }
  2551.  
  2552. /* DECL is an anonymous union.  CLEANUP is a cleanup for DECL.
  2553.    DECL_ELTS is the list of elements that belong to DECL's type.
  2554.    In each, the TREE_VALUE is a VAR_DECL, and the TREE_PURPOSE a cleanup.  */
  2555.  
  2556. void
  2557. expand_anon_union_decl (decl, cleanup, decl_elts)
  2558.      tree decl, cleanup, decl_elts;
  2559. {
  2560.   struct nesting *thisblock = block_stack;
  2561.   rtx x;
  2562.  
  2563.   expand_decl (decl, cleanup);
  2564.   x = DECL_RTL (decl);
  2565.  
  2566.   while (decl_elts)
  2567.     {
  2568.       tree decl_elt = TREE_VALUE (decl_elts);
  2569.       tree cleanup_elt = TREE_PURPOSE (decl_elts);
  2570.       enum machine_mode tmode = TYPE_MODE (TREE_TYPE (decl_elt));
  2571.  
  2572.       if (GET_CODE (x) == MEM)
  2573.     {
  2574.       /* @@ calling `change_address' means that we cannot
  2575.          be at top-level, since `memory_address' might try
  2576.          to kick this address into a register, which won't
  2577.          work.  Will this work?  */
  2578.       rtx new = gen_rtx (MEM, tmode, XEXP (x, 0));
  2579.       DECL_RTL (decl_elt) = new;
  2580.       MEM_VOLATILE_P (new) = MEM_VOLATILE_P (x);
  2581.       RTX_UNCHANGING_P (new) = RTX_UNCHANGING_P (x);
  2582.       MEM_IN_STRUCT_P (new) = MEM_IN_STRUCT_P (x);
  2583.     }
  2584.       else
  2585.     DECL_RTL (decl_elt) = gen_rtx (SUBREG, tmode, x, 0);
  2586.  
  2587.       /* Record the cleanup if there is one.  */
  2588.  
  2589.       if (cleanup != 0)
  2590.     thisblock->data.block.cleanups
  2591.       = temp_tree_cons (decl_elt, cleanup_elt,
  2592.                 thisblock->data.block.cleanups);
  2593.  
  2594.       decl_elts = TREE_CHAIN (decl_elts);
  2595.     }
  2596. }
  2597.  
  2598. /* Expand a list of cleanups LIST.
  2599.    Elements may be expressions or may be nested lists.
  2600.  
  2601.    If DONT_DO is nonnull, then any list-element
  2602.    whose TREE_PURPOSE matches DONT_DO is omitted.
  2603.    This is sometimes used to avoid a cleanup associated with
  2604.    a value that is being returned out of the scope.  */
  2605.  
  2606. static void
  2607. expand_cleanups (list, dont_do)
  2608.      tree list;
  2609.      tree dont_do;
  2610. {
  2611.   tree tail;
  2612.   for (tail = list; tail; tail = TREE_CHAIN (tail))
  2613.     if (dont_do == 0 || TREE_PURPOSE (tail) != dont_do)
  2614.       {
  2615.     if (TREE_CODE (TREE_VALUE (tail)) == TREE_LIST)
  2616.       expand_cleanups (TREE_VALUE (tail), dont_do);
  2617.     else
  2618.       expand_expr (TREE_VALUE (tail), const0_rtx, VOIDmode, 0);
  2619.       }
  2620. }
  2621.  
  2622. /* Expand a list of cleanups for a goto fixup.
  2623.    The expansion is put into the insn chain after the insn *BEFORE_JUMP
  2624.    and *BEFORE_JUMP is set to the insn that now comes before the jump.  */
  2625.  
  2626. static void
  2627. fixup_cleanups (list, before_jump)
  2628.      tree list;
  2629.      rtx *before_jump;
  2630. {
  2631.   rtx beyond_jump = get_last_insn ();
  2632.   rtx new_before_jump;
  2633.  
  2634.   expand_cleanups (list, 0);
  2635.   /* Pop any pushes done in the cleanups,
  2636.      in case function is about to return.  */
  2637.   do_pending_stack_adjust ();
  2638.  
  2639.   new_before_jump = get_last_insn ();
  2640.  
  2641.   if (beyond_jump != new_before_jump)
  2642.     {
  2643.       /* If cleanups expand to nothing, don't reorder.  */
  2644.       reorder_insns (NEXT_INSN (beyond_jump), new_before_jump, *before_jump);
  2645.       *before_jump = new_before_jump;
  2646.     }
  2647. }
  2648.  
  2649. /* Move all cleanups from the current block_stack
  2650.    to the containing block_stack, where they are assumed to
  2651.    have been created.  If anything can cause a temporary to
  2652.    be created, but not expanded for more than one level of
  2653.    block_stacks, then this code will have to change.  */
  2654.  
  2655. void
  2656. move_cleanups_up ()
  2657. {
  2658.   struct nesting *block = block_stack;
  2659.   struct nesting *outer = block->next;
  2660.  
  2661.   outer->data.block.cleanups
  2662.     = chainon (block->data.block.cleanups,
  2663.            outer->data.block.cleanups);
  2664.   block->data.block.cleanups = 0;
  2665. }
  2666.  
  2667. int
  2668. this_contour_has_cleanups_p ()
  2669. {
  2670.   return block_stack && block_stack->data.block.cleanups != 0;
  2671. }
  2672.  
  2673. /* Return 1 if there are any pending cleanups at this point.
  2674.    If THIS_CONTOUR is nonzero, check the current contour as well.
  2675.    Otherwise, look only at the contours that enclose this one.  */
  2676.  
  2677. int
  2678. any_pending_cleanups (this_contour)
  2679.      int this_contour;
  2680. {
  2681.   struct nesting *block;
  2682.  
  2683.   if (block_stack == 0)
  2684.     return 0;
  2685.  
  2686.   if (this_contour && block_stack->data.block.cleanups != NULL)
  2687.     return 1;
  2688.   if (block_stack->data.block.cleanups == 0
  2689.       && (block_stack->data.block.outer_cleanups == 0
  2690. #if 0
  2691.       || block_stack->data.block.outer_cleanups == empty_cleanup_list
  2692. #endif
  2693.       ))
  2694.     return 0;
  2695.  
  2696.   for (block = block_stack->next; block; block = block->next)
  2697.     if (block->data.block.cleanups != 0)
  2698.       return 1;
  2699.  
  2700.   return 0;
  2701. }
  2702.  
  2703. /* Enter a case (Pascal) or switch (C) statement.
  2704.    Push a block onto case_stack and nesting_stack
  2705.    to accumulate the case-labels that are seen
  2706.    and to record the labels generated for the statement.
  2707.  
  2708.    EXIT_FLAG is nonzero if `exit_something' should exit this case stmt.
  2709.    Otherwise, this construct is transparent for `exit_something'.
  2710.  
  2711.    EXPR is the index-expression to be dispatched on.
  2712.    TYPE is its nominal type.  We could simply convert EXPR to this type,
  2713.    but instead we take short cuts.  */
  2714.  
  2715. void
  2716. expand_start_case (exit_flag, expr, type)
  2717.      int exit_flag;
  2718.      tree expr;
  2719.      tree type;
  2720. {
  2721.   register struct nesting *thiscase
  2722.     = (struct nesting *) obstack_alloc (&stmt_obstack, sizeof (struct nesting));
  2723.  
  2724.   /* Make an entry on case_stack for the case we are entering.  */
  2725.  
  2726.   thiscase->next = case_stack;
  2727.   thiscase->all = nesting_stack;
  2728.   thiscase->depth = ++nesting_depth;
  2729.   thiscase->exit_label = exit_flag ? gen_label_rtx () : 0;
  2730.   thiscase->data.case_stmt.case_list = 0;
  2731.   thiscase->data.case_stmt.index_expr = expr;
  2732.   thiscase->data.case_stmt.nominal_type = type;
  2733.   thiscase->data.case_stmt.default_label = 0;
  2734.   thiscase->data.case_stmt.num_ranges = 0;
  2735.   case_stack = thiscase;
  2736.   nesting_stack = thiscase;
  2737.  
  2738.   do_pending_stack_adjust ();
  2739.  
  2740.   /* Make sure case_stmt.start points to something that won't
  2741.      need any transformation before expand_end_case.  */
  2742.   emit_note (0, NOTE_INSN_DELETED);
  2743.  
  2744.   thiscase->data.case_stmt.start = get_last_insn ();
  2745. }
  2746.  
  2747. /* Start a "dummy case statement" within which case labels are invalid
  2748.    and are not connected to any larger real case statement.
  2749.    This can be used if you don't want to let a case statement jump
  2750.    into the middle of certain kinds of constructs.  */
  2751.  
  2752. void
  2753. expand_start_case_dummy ()
  2754. {
  2755.   register struct nesting *thiscase
  2756.     = (struct nesting *) obstack_alloc (&stmt_obstack, sizeof (struct nesting));
  2757.  
  2758.   /* Make an entry on case_stack for the dummy.  */
  2759.  
  2760.   thiscase->next = case_stack;
  2761.   thiscase->all = nesting_stack;
  2762.   thiscase->depth = ++nesting_depth;
  2763.   thiscase->exit_label = 0;
  2764.   thiscase->data.case_stmt.case_list = 0;
  2765.   thiscase->data.case_stmt.start = 0;
  2766.   thiscase->data.case_stmt.nominal_type = 0;
  2767.   thiscase->data.case_stmt.default_label = 0;
  2768.   thiscase->data.case_stmt.num_ranges = 0;
  2769.   case_stack = thiscase;
  2770.   nesting_stack = thiscase;
  2771. }
  2772.  
  2773. /* End a dummy case statement.  */
  2774.  
  2775. void
  2776. expand_end_case_dummy ()
  2777. {
  2778.   POPSTACK (case_stack);
  2779. }
  2780.  
  2781. /* Accumulate one case or default label inside a case or switch statement.
  2782.    VALUE is the value of the case (a null pointer, for a default label).
  2783.  
  2784.    If not currently inside a case or switch statement, return 1 and do
  2785.    nothing.  The caller will print a language-specific error message.
  2786.    If VALUE is a duplicate or overlaps, return 2 and do nothing.
  2787.    If VALUE is out of range, return 3 and do nothing.
  2788.    Return 0 on success.
  2789.  
  2790.    Extended to handle range statements, should they ever
  2791.    be adopted.  */
  2792.  
  2793. int
  2794. pushcase (value, label)
  2795.      register tree value;
  2796.      register tree label;
  2797. {
  2798.   register struct case_node **l;
  2799.   register struct case_node *n;
  2800.   tree index_type;
  2801.   tree nominal_type;
  2802.  
  2803.   /* Fail if not inside a real case statement.  */
  2804.   if (! (case_stack && case_stack->data.case_stmt.start))
  2805.     return 1;
  2806.  
  2807.   index_type = TREE_TYPE (case_stack->data.case_stmt.index_expr);
  2808.   nominal_type = case_stack->data.case_stmt.nominal_type;
  2809.  
  2810.   /* If the index is erroneous, avoid more problems: pretend to succeed.  */
  2811.   if (index_type == error_mark_node)
  2812.     return 0;
  2813.  
  2814.   /* Convert VALUE to the type in which the comparisons are nominally done.  */
  2815.   if (value != 0)
  2816.     value = convert (nominal_type, value);
  2817.  
  2818.   /* Fail if this value is out of range for the actual type of the index
  2819.      (which may be narrower than NOMINAL_TYPE).  */
  2820.   if (value != 0 && ! int_fits_type_p (value, index_type))
  2821.     return 3;
  2822.  
  2823.   /* Fail if this is a duplicate or overlaps another entry.  */
  2824.   if (value == 0)
  2825.     {
  2826.       if (case_stack->data.case_stmt.default_label != 0)
  2827.     return 2;
  2828.       case_stack->data.case_stmt.default_label = label;
  2829.     }
  2830.   else
  2831.     {
  2832.       /* Find the elt in the chain before which to insert the new value,
  2833.      to keep the chain sorted in increasing order.
  2834.      But report an error if this element is a duplicate.  */
  2835.       for (l = &case_stack->data.case_stmt.case_list;
  2836.        /* Keep going past elements distinctly less than VALUE.  */
  2837.        *l != 0 && tree_int_cst_lt ((*l)->high, value);
  2838.        l = &(*l)->right)
  2839.     ;
  2840.       if (*l)
  2841.     {
  2842.       /* Element we will insert before must be distinctly greater;
  2843.          overlap means error.  */
  2844.       if (! tree_int_cst_lt (value, (*l)->low))
  2845.         return 2;
  2846.     }
  2847.  
  2848.       /* Add this label to the chain, and succeed.
  2849.      Copy VALUE so it is on temporary rather than momentary
  2850.      obstack and will thus survive till the end of the case statement.  */
  2851.       n = (struct case_node *) oballoc (sizeof (struct case_node));
  2852.       n->left = 0;
  2853.       n->right = *l;
  2854.       n->high = n->low = copy_node (value);
  2855.       n->code_label = label;
  2856.       n->test_label = 0;
  2857.       *l = n;
  2858.     }
  2859.  
  2860.   expand_label (label);
  2861.   return 0;
  2862. }
  2863.  
  2864. /* Like pushcase but this case applies to all values
  2865.    between VALUE1 and VALUE2 (inclusive).
  2866.    The return value is the same as that of pushcase
  2867.    but there is one additional error code:
  2868.    4 means the specified range was empty.
  2869.  
  2870.    Note that this does not currently work, since expand_end_case
  2871.    has yet to be extended to handle RANGE_EXPRs.  */
  2872.  
  2873. int
  2874. pushcase_range (value1, value2, label)
  2875.      register tree value1, value2;
  2876.      register tree label;
  2877. {
  2878.   register struct case_node **l;
  2879.   register struct case_node *n;
  2880.   tree index_type;
  2881.   tree nominal_type;
  2882.  
  2883.   /* Fail if not inside a real case statement.  */
  2884.   if (! (case_stack && case_stack->data.case_stmt.start))
  2885.     return 1;
  2886.  
  2887.   index_type = TREE_TYPE (case_stack->data.case_stmt.index_expr);
  2888.   nominal_type = case_stack->data.case_stmt.nominal_type;
  2889.  
  2890.   /* If the index is erroneous, avoid more problems: pretend to succeed.  */
  2891.   if (index_type == error_mark_node)
  2892.     return 0;
  2893.  
  2894.   /* Convert VALUEs to type in which the comparisons are nominally done.  */
  2895.   if (value1 != 0)
  2896.     value1 = convert (nominal_type, value1);
  2897.   if (value2 != 0)
  2898.     value2 = convert (nominal_type, value2);
  2899.  
  2900.   /* Fail if these values are out of range.  */
  2901.   if (value1 != 0 && ! int_fits_type_p (value1, index_type))
  2902.     return 3;
  2903.  
  2904.   if (value2 != 0 && ! int_fits_type_p (value2, index_type))
  2905.     return 3;
  2906.  
  2907.   /* Fail if the range is empty.  */
  2908.   if (tree_int_cst_lt (value2, value1))
  2909.     return 4;
  2910.  
  2911.   /* If the bounds are equal, turn this into the one-value case.  */
  2912.   if (tree_int_cst_equal (value1, value2))
  2913.     return pushcase (value1, label);
  2914.  
  2915.   /* Find the elt in the chain before which to insert the new value,
  2916.      to keep the chain sorted in increasing order.
  2917.      But report an error if this element is a duplicate.  */
  2918.   for (l = &case_stack->data.case_stmt.case_list;
  2919.        /* Keep going past elements distinctly less than this range.  */
  2920.        *l != 0 && tree_int_cst_lt ((*l)->high, value1);
  2921.        l = &(*l)->right)
  2922.     ;
  2923.   if (*l)
  2924.     {
  2925.       /* Element we will insert before must be distinctly greater;
  2926.      overlap means error.  */
  2927.       if (! tree_int_cst_lt (value2, (*l)->low))
  2928.     return 2;
  2929.     }
  2930.  
  2931.   /* Add this label to the chain, and succeed.
  2932.      Copy VALUE1, VALUE2 so they are on temporary rather than momentary
  2933.      obstack and will thus survive till the end of the case statement.  */
  2934.  
  2935.   n = (struct case_node *) oballoc (sizeof (struct case_node));
  2936.   n->left = 0;
  2937.   n->right = *l;
  2938.   n->low = copy_node (value1);
  2939.   n->high = copy_node (value2);
  2940.   n->code_label = label;
  2941.   n->test_label = 0;
  2942.   *l = n;
  2943.  
  2944.   expand_label (label);
  2945.  
  2946.   case_stack->data.case_stmt.num_ranges++;
  2947.  
  2948.   return 0;
  2949. }
  2950.  
  2951. /* Check that all enumeration literals are covered by the case
  2952.    expressions of a switch.  Also, warn if there are any extra
  2953.    switch cases that are *not* elements of the enumerated type. */
  2954.  
  2955. void
  2956. check_for_full_enumeration_handling (type)
  2957.      tree type;
  2958. {
  2959.   register struct case_node *n;
  2960.   register tree chain;
  2961.  
  2962.   /* The time complexity of this loop is currently O(N * M), with
  2963.      N being the number of enumerals in the enumerated type, and 
  2964.      M being the number of case expressions in the switch. */
  2965.              
  2966.   for (chain = TYPE_VALUES (type);
  2967.        chain;
  2968.        chain = TREE_CHAIN (chain))
  2969.     {
  2970.       /* Find a match between enumeral and case expression, if possible.
  2971.      Quit looking when we've gone too far (since case expressions
  2972.      are kept sorted in ascending order).  Warn about enumerals not
  2973.      handled in the switch statement case expression list. */
  2974.  
  2975.       for (n = case_stack->data.case_stmt.case_list; 
  2976.        n && tree_int_cst_lt (n->high, TREE_VALUE (chain));
  2977.        n = n->right)
  2978.     ;
  2979.  
  2980.       if (!(n && tree_int_cst_equal (n->low, TREE_VALUE (chain))))
  2981.     warning ("enumerated value `%s' not handled in switch",
  2982.          IDENTIFIER_POINTER (TREE_PURPOSE (chain)));
  2983.     }
  2984.  
  2985.   /* Now we go the other way around; we warn if there are case 
  2986.      expressions that don't correspond to enumerals.  This can
  2987.      occur since C and C++ don't enforce type-checking of 
  2988.      assignments to enumeration variables. */
  2989.  
  2990.   for (n = case_stack->data.case_stmt.case_list; n; n = n->right)
  2991.     {
  2992.       for (chain = TYPE_VALUES (type);
  2993.        chain && !tree_int_cst_equal (n->low, TREE_VALUE (chain)); 
  2994.        chain = TREE_CHAIN (chain))
  2995.     ;
  2996.  
  2997.       if (!chain)
  2998.     warning ("case value `%d' not in enumerated type `%s'",
  2999.          TREE_INT_CST_LOW (n->low), 
  3000.          IDENTIFIER_POINTER (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
  3001.                      ? TYPE_NAME (type)
  3002.                      : DECL_NAME (TYPE_NAME (type))));
  3003.     }
  3004. }
  3005.  
  3006. /* Terminate a case (Pascal) or switch (C) statement
  3007.    in which CASE_INDEX is the expression to be tested.
  3008.    Generate the code to test it and jump to the right place.  */
  3009.  
  3010. void
  3011. expand_end_case (orig_index)
  3012.      tree orig_index;
  3013. {
  3014.   tree minval, maxval, range;
  3015.   rtx default_label = 0;
  3016.   register struct case_node *n;
  3017.   int count;
  3018.   rtx index;
  3019.   rtx table_label = gen_label_rtx ();
  3020.   int ncases;
  3021.   rtx *labelvec;
  3022.   register int i;
  3023.   rtx before_case;
  3024.   register struct nesting *thiscase = case_stack;
  3025.   tree index_expr = thiscase->data.case_stmt.index_expr;
  3026.   int unsignedp = TREE_UNSIGNED (TREE_TYPE (index_expr));
  3027.  
  3028.   do_pending_stack_adjust ();
  3029.  
  3030.   /* An ERROR_MARK occurs for various reasons including invalid data type.  */
  3031.   if (TREE_TYPE (index_expr) != error_mark_node)
  3032.     {
  3033.       /* If switch expression was an enumerated type, check that all
  3034.      enumeration literals are covered by the cases.
  3035.      No sense trying this if there's a default case, however.  */
  3036.  
  3037.       if (!thiscase->data.case_stmt.default_label 
  3038.       && TREE_CODE (TREE_TYPE (orig_index)) == ENUMERAL_TYPE
  3039.       && TREE_CODE (index_expr) != INTEGER_CST
  3040.       && warn_switch)
  3041.     check_for_full_enumeration_handling (TREE_TYPE (orig_index));
  3042.  
  3043.       /* If we don't have a default-label, create one here,
  3044.      after the body of the switch.  */
  3045.       if (thiscase->data.case_stmt.default_label == 0)
  3046.     {
  3047.       thiscase->data.case_stmt.default_label
  3048.         = build_decl (LABEL_DECL, NULL_TREE, NULL_TREE);
  3049.       expand_label (thiscase->data.case_stmt.default_label);
  3050.     }
  3051.       default_label = label_rtx (thiscase->data.case_stmt.default_label);
  3052.  
  3053.       before_case = get_last_insn ();
  3054.  
  3055.       /* Simplify the case-list before we count it.  */
  3056.       group_case_nodes (thiscase->data.case_stmt.case_list);
  3057.  
  3058.       /* Get upper and lower bounds of case values.
  3059.      Also convert all the case values to the index expr's data type.  */
  3060.  
  3061.       count = 0;
  3062.       for (n = thiscase->data.case_stmt.case_list; n; n = n->right)
  3063.     {
  3064.       /* Check low and high label values are integers.  */
  3065.       if (TREE_CODE (n->low) != INTEGER_CST)
  3066.         abort ();
  3067.       if (TREE_CODE (n->high) != INTEGER_CST)
  3068.         abort ();
  3069.  
  3070.       n->low = convert (TREE_TYPE (index_expr), n->low);
  3071.       n->high = convert (TREE_TYPE (index_expr), n->high);
  3072.  
  3073.       /* Count the elements and track the largest and smallest
  3074.          of them (treating them as signed even if they are not).  */
  3075.       if (count++ == 0)
  3076.         {
  3077.           minval = n->low;
  3078.           maxval = n->high;
  3079.         }
  3080.       else
  3081.         {
  3082.           if (INT_CST_LT (n->low, minval))
  3083.         minval = n->low;
  3084.           if (INT_CST_LT (maxval, n->high))
  3085.         maxval = n->high;
  3086.         }
  3087.       /* A range counts double, since it requires two compares.  */
  3088.       if (! tree_int_cst_equal (n->low, n->high))
  3089.         count++;
  3090.     }
  3091.  
  3092.       /* Compute span of values.  */
  3093.       if (count != 0)
  3094.     range = combine (MINUS_EXPR, maxval, minval);
  3095.  
  3096.       if (count == 0 || TREE_CODE (TREE_TYPE (index_expr)) == ERROR_MARK)
  3097.     {
  3098.       expand_expr (index_expr, const0_rtx, VOIDmode, 0);
  3099.       emit_queue ();
  3100.       emit_jump (default_label);
  3101.     }
  3102.       /* If range of values is much bigger than number of values,
  3103.      make a sequence of conditional branches instead of a dispatch.
  3104.      If the switch-index is a constant, do it this way
  3105.      because we can optimize it.  */
  3106.       else if (TREE_INT_CST_HIGH (range) != 0
  3107. #ifdef HAVE_casesi
  3108.            || count < 4
  3109. #else
  3110.            /* If machine does not have a case insn that compares the
  3111.           bounds, this means extra overhead for dispatch tables
  3112.           which raises the threshold for using them.  */
  3113.            || count < 5
  3114. #endif
  3115.            || (unsigned) (TREE_INT_CST_LOW (range)) > 10 * count
  3116.            || TREE_CODE (index_expr) == INTEGER_CST)
  3117.     {
  3118.       index = expand_expr (index_expr, 0, VOIDmode, 0);
  3119.  
  3120.       /* If the index is a short or char that we do not have
  3121.          an insn to handle comparisons directly, convert it to
  3122.          a full integer now, rather than letting each comparison
  3123.          generate the conversion.  */
  3124.  
  3125.       if ((GET_MODE (index) == QImode || GET_MODE (index) == HImode)
  3126.           && (cmp_optab->handlers[(int) GET_MODE(index)].insn_code
  3127.           == CODE_FOR_nothing))
  3128.         index = convert_to_mode (SImode, index, unsignedp);
  3129.       
  3130.       emit_queue ();
  3131.       do_pending_stack_adjust ();
  3132.  
  3133.       index = protect_from_queue (index, 0);
  3134.       if (GET_CODE (index) == MEM)
  3135.         index = copy_to_reg (index);
  3136.       if (GET_CODE (index) == CONST_INT
  3137.           || TREE_CODE (index_expr) == INTEGER_CST)
  3138.         {
  3139.           /* Make a tree node with the proper constant value
  3140.          if we don't already have one.  */
  3141.           if (TREE_CODE (index_expr) != INTEGER_CST)
  3142.         {
  3143.           index_expr
  3144.             = build_int_2 (INTVAL (index),
  3145.                    !unsignedp && INTVAL (index) >= 0 ? 0 : -1);
  3146.           index_expr = convert (TREE_TYPE (index_expr), index_expr);
  3147.         }
  3148.  
  3149.           /* For constant index expressions we need only
  3150.          issue a unconditional branch to the appropriate
  3151.          target code.  The job of removing any unreachable
  3152.          code is left to the optimisation phase if the
  3153.          "-O" option is specified.  */
  3154.           for (n = thiscase->data.case_stmt.case_list;
  3155.            n;
  3156.            n = n->right)
  3157.         {
  3158.           if (! tree_int_cst_lt (index_expr, n->low)
  3159.               && ! tree_int_cst_lt (n->high, index_expr))
  3160.             break;
  3161.         }
  3162.           if (n)
  3163.         emit_jump (label_rtx (n->code_label));
  3164.           else
  3165.         emit_jump (default_label);
  3166.         }
  3167.       else
  3168.         {
  3169.           /* If the index expression is not constant we generate
  3170.          a binary decision tree to select the appropriate
  3171.          target code.  This is done as follows:
  3172.  
  3173.          The list of cases is rearranged into a binary tree,
  3174.          nearly optimal assuming equal probability for each case.
  3175.  
  3176.          The tree is transformed into RTL, eliminating
  3177.          redundant test conditions at the same time.
  3178.  
  3179.          If program flow could reach the end of the
  3180.          decision tree an unconditional jump to the
  3181.          default code is emitted.  */
  3182.           if (optimize
  3183.           && TREE_CODE (TREE_TYPE (orig_index)) != ENUMERAL_TYPE)
  3184.         estimate_case_costs (thiscase->data.case_stmt.case_list,
  3185.                      default_label);
  3186.           balance_case_nodes (&thiscase->data.case_stmt.case_list, 0);
  3187.           emit_case_nodes (index, thiscase->data.case_stmt.case_list,
  3188.                    default_label, unsignedp);
  3189.           emit_jump_if_reachable (default_label);
  3190.         }
  3191.     }
  3192.       else
  3193.     {
  3194. #ifdef HAVE_casesi
  3195.       /* Convert the index to SImode.  */
  3196.       if (TYPE_MODE (TREE_TYPE (index_expr)) == DImode)
  3197.         {
  3198.           index_expr = build (MINUS_EXPR, TREE_TYPE (index_expr),
  3199.                   index_expr, minval);
  3200.           minval = integer_zero_node;
  3201.         }
  3202.       if (TYPE_MODE (TREE_TYPE (index_expr)) != SImode)
  3203.         index_expr = convert (type_for_size (GET_MODE_BITSIZE (SImode), 0),
  3204.                   index_expr);
  3205.       index = expand_expr (index_expr, 0, VOIDmode, 0);
  3206.       emit_queue ();
  3207.       index = protect_from_queue (index, 0);
  3208.       do_pending_stack_adjust ();
  3209.  
  3210.       emit_jump_insn (gen_casesi (index, expand_expr (minval, 0, VOIDmode, 0),
  3211.                       expand_expr (range, 0, VOIDmode, 0),
  3212.                       table_label, default_label));
  3213. #else
  3214. #ifdef HAVE_tablejump
  3215.       index_expr = convert (type_for_size (GET_MODE_BITSIZE (SImode), 0),
  3216.                 build (MINUS_EXPR, TREE_TYPE (index_expr),
  3217.                        index_expr, minval));
  3218.       index = expand_expr (index_expr, 0, VOIDmode, 0);
  3219.       emit_queue ();
  3220.       index = protect_from_queue (index, 0);
  3221.       do_pending_stack_adjust ();
  3222.  
  3223.       do_tablejump (index,
  3224.             gen_rtx (CONST_INT, VOIDmode, TREE_INT_CST_LOW (range)),
  3225.             table_label, default_label);
  3226. #else
  3227.       lossage;
  3228. #endif                /* not HAVE_tablejump */
  3229. #endif                /* not HAVE_casesi */
  3230.  
  3231.       /* Get table of labels to jump to, in order of case index.  */
  3232.  
  3233.       ncases = TREE_INT_CST_LOW (range) + 1;
  3234.       labelvec = (rtx *) alloca (ncases * sizeof (rtx));
  3235.       bzero (labelvec, ncases * sizeof (rtx));
  3236.  
  3237.       for (n = thiscase->data.case_stmt.case_list; n; n = n->right)
  3238.         {
  3239.           register int i
  3240.         = TREE_INT_CST_LOW (n->low) - TREE_INT_CST_LOW (minval);
  3241.  
  3242.           while (i + TREE_INT_CST_LOW (minval)
  3243.              <= TREE_INT_CST_LOW (n->high))
  3244.         labelvec[i++]
  3245.           = gen_rtx (LABEL_REF, Pmode, label_rtx (n->code_label));
  3246.         }
  3247.  
  3248.       /* Fill in the gaps with the default.  */
  3249.       for (i = 0; i < ncases; i++)
  3250.         if (labelvec[i] == 0)
  3251.           labelvec[i] = gen_rtx (LABEL_REF, Pmode, default_label);
  3252.  
  3253.       /* Output the table */
  3254.       emit_label (table_label);
  3255.  
  3256. #ifdef CASE_VECTOR_PC_RELATIVE
  3257.       emit_jump_insn (gen_rtx (ADDR_DIFF_VEC, CASE_VECTOR_MODE,
  3258.                    gen_rtx (LABEL_REF, Pmode, table_label),
  3259.                    gen_rtvec_v (ncases, labelvec)));
  3260. #else
  3261.       emit_jump_insn (gen_rtx (ADDR_VEC, CASE_VECTOR_MODE,
  3262.                    gen_rtvec_v (ncases, labelvec)));
  3263. #endif
  3264.       /* If the case insn drops through the table,
  3265.          after the table we must jump to the default-label.
  3266.          Otherwise record no drop-through after the table.  */
  3267. #ifdef CASE_DROPS_THROUGH
  3268.       emit_jump (default_label);
  3269. #else
  3270.       emit_barrier ();
  3271. #endif
  3272.     }
  3273.  
  3274.       reorder_insns (NEXT_INSN (before_case), get_last_insn (),
  3275.              thiscase->data.case_stmt.start);
  3276.     }
  3277.   if (thiscase->exit_label)
  3278.     emit_label (thiscase->exit_label);
  3279.  
  3280.   POPSTACK (case_stack);
  3281. }
  3282.  
  3283. /* See case.c for CASE-handling code.  */
  3284.  
  3285. /* Allocate fixed slots in the stack frame of the current function.  */
  3286.  
  3287. /* Return size needed for stack frame based on slots so far allocated.  */
  3288.  
  3289. int
  3290. get_frame_size ()
  3291. {
  3292. #ifdef FRAME_GROWS_DOWNWARD
  3293.   return -frame_offset + STARTING_FRAME_OFFSET;
  3294. #else
  3295.   return frame_offset - STARTING_FRAME_OFFSET;
  3296. #endif
  3297. }
  3298.  
  3299. /* Allocate a stack slot of SIZE bytes and return a MEM rtx for it
  3300.    with machine mode MODE.  */
  3301.  
  3302. rtx
  3303. assign_stack_local (mode, size)
  3304.      enum machine_mode mode;
  3305.      int size;
  3306. {
  3307.   register rtx x, addr;
  3308.   int bigend_correction = 0;
  3309.  
  3310.   frame_pointer_needed = 1;
  3311.  
  3312.   /* Make each stack slot a multiple of the main allocation unit.  */
  3313.   size = (((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
  3314.        / (BIGGEST_ALIGNMENT / BITS_PER_UNIT))
  3315.       * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
  3316.  
  3317.   /* On a big-endian machine, if we are allocating more space than we will use,
  3318.      use the least significant bytes of those that are allocated.  */
  3319. #ifdef BYTES_BIG_ENDIAN
  3320.   if (mode != BLKmode)
  3321.     bigend_correction = size - GET_MODE_SIZE (mode);
  3322. #endif
  3323.  
  3324. #ifdef FRAME_GROWS_DOWNWARD
  3325.   frame_offset -= size;
  3326. #endif
  3327.   addr = gen_rtx (PLUS, Pmode, frame_pointer_rtx,
  3328.           gen_rtx (CONST_INT, VOIDmode,
  3329.                (frame_offset + bigend_correction)));
  3330. #ifndef FRAME_GROWS_DOWNWARD
  3331.   frame_offset += size;
  3332. #endif
  3333.  
  3334.   if (! memory_address_p (mode, addr))
  3335.     invalid_stack_slot = 1;
  3336.  
  3337.   x = gen_rtx (MEM, mode, addr);
  3338.  
  3339.   stack_slot_list = gen_rtx (EXPR_LIST, VOIDmode, x, stack_slot_list);
  3340.  
  3341.   return x;
  3342. }
  3343.  
  3344. /* Retroactively move an auto variable from a register to a stack slot.
  3345.    This is done when an address-reference to the variable is seen.  */
  3346.  
  3347. void
  3348. put_var_into_stack (decl)
  3349.      tree decl;
  3350. {
  3351.   register rtx reg = DECL_RTL (decl);
  3352.   register rtx new;
  3353.  
  3354.   /* No need to do anything if decl has no rtx yet
  3355.      since in that case caller is setting TREE_ADDRESSABLE
  3356.      and a stack slot will be assigned when the rtl is made.  */
  3357.   if (reg == 0)
  3358.     return;
  3359.   if (GET_CODE (reg) != REG)
  3360.     return;
  3361.  
  3362.   new = parm_stack_loc (reg);
  3363.   if (new == 0)
  3364.     new = assign_stack_local (GET_MODE (reg), GET_MODE_SIZE (GET_MODE (reg)));
  3365.  
  3366.   XEXP (reg, 0) = XEXP (new, 0);
  3367.   /* `volatil' bit means one thing for MEMs, another entirely for REGs.  */
  3368.   REG_USERVAR_P (reg) = 0;
  3369.   PUT_CODE (reg, MEM);
  3370.  
  3371.   /* If this is a memory ref that contains aggregate components,
  3372.      mark it as such for cse and loop optimize.  */
  3373.   MEM_IN_STRUCT_P (reg)
  3374.     = (TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE
  3375.        || TREE_CODE (TREE_TYPE (decl)) == RECORD_TYPE
  3376.        || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE);
  3377.  
  3378.   fixup_var_refs (reg);
  3379. }
  3380.  
  3381. static void
  3382. fixup_var_refs (var)
  3383.      rtx var;
  3384. {
  3385.   extern rtx sequence_stack;
  3386.   rtx stack = sequence_stack;
  3387.   tree pending;
  3388.  
  3389.   stack = sequence_stack;
  3390.  
  3391.   /* Must scan all insns for stack-refs that exceed the limit.  */
  3392.   fixup_var_refs_insns (var, get_insns (), stack == 0);
  3393.  
  3394.   /* Scan all pending sequences too.  */
  3395.   for (; stack; stack = XEXP (XEXP (stack, 1), 1))
  3396.     {
  3397.       push_to_sequence (XEXP (stack, 0));
  3398.       fixup_var_refs_insns (var, XEXP (stack, 0),
  3399.                 XEXP (XEXP (stack, 1), 1) == 0);
  3400.       /* Update remembered end of sequence
  3401.      in case we added an insn at the end.  */
  3402.       XEXP (XEXP (stack, 1), 0) = get_last_insn ();
  3403.       end_sequence ();
  3404.     }
  3405.  
  3406.   /* Scan all waiting RTL_EXPRs too.  */
  3407.   for (pending = rtl_expr_chain; pending; pending = TREE_CHAIN (pending))
  3408.     {
  3409.       rtx seq = RTL_EXPR_SEQUENCE (TREE_VALUE (pending));
  3410.       if (seq != const0_rtx && seq != 0)
  3411.     {
  3412.       push_to_sequence (seq);
  3413.       fixup_var_refs_insns (var, seq, 0);
  3414.       end_sequence ();
  3415.     }
  3416.     }
  3417. }
  3418.  
  3419. /* Scan the insn-chain starting with INSN for refs to VAR
  3420.    and fix them up.  TOPLEVEL is nonzero if this chain is the
  3421.    main chain of insns for the current function.  */
  3422.  
  3423. static void
  3424. fixup_var_refs_insns (var, insn, toplevel)
  3425.      rtx var;
  3426.      rtx insn;
  3427.      int toplevel;
  3428. {
  3429.   while (insn)
  3430.     {
  3431.       rtx next = NEXT_INSN (insn);
  3432.       rtx note;
  3433.       if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
  3434.       || GET_CODE (insn) == JUMP_INSN)
  3435.     {
  3436.       /* The insn to load VAR from a home in the arglist
  3437.          is now a no-op.  When we see it, just delete it.  */
  3438.       if (toplevel
  3439.           && GET_CODE (PATTERN (insn)) == SET
  3440.           && SET_DEST (PATTERN (insn)) == var
  3441.           && rtx_equal_p (SET_SRC (PATTERN (insn)), var))
  3442.         {
  3443.           next = delete_insn (insn);
  3444.           if (insn == last_parm_insn)
  3445.         last_parm_insn = PREV_INSN (next);
  3446.         }
  3447.       else
  3448.         fixup_var_refs_1 (var, PATTERN (insn), insn);
  3449.       /* Also fix up any invalid exprs in the REG_NOTES of this insn.
  3450.          But don't touch other insns referred to by reg-notes;
  3451.          we will get them elsewhere.  */
  3452.       for (note = REG_NOTES (insn); note; note = XEXP (note, 1))
  3453.         if (GET_CODE (note) != INSN_LIST)
  3454.           XEXP (note, 0) = walk_fixup_memory_subreg (XEXP (note, 0), insn);
  3455.     }
  3456.       insn = next;
  3457.     }
  3458. }
  3459.  
  3460. static rtx
  3461. fixup_var_refs_1 (var, x, insn)
  3462.      register rtx var;
  3463.      register rtx x;
  3464.      rtx insn;
  3465. {
  3466.   register int i;
  3467.   RTX_CODE code = GET_CODE (x);
  3468.   register char *fmt;
  3469.   register rtx tem;
  3470.  
  3471.   switch (code)
  3472.     {
  3473.     case MEM:
  3474.       if (var == x)
  3475.     {
  3476.       x = fixup_stack_1 (x, insn);
  3477.       tem = gen_reg_rtx (GET_MODE (x));
  3478.       /* Put new insn before a CALL, before any USEs before it.  */
  3479.       if (GET_CODE (insn) == CALL_INSN)
  3480.         while (PREV_INSN (insn) != 0 && GET_CODE (PREV_INSN (insn)) == INSN
  3481.            && GET_CODE (PATTERN (PREV_INSN (insn))) == USE)
  3482.           insn = PREV_INSN (insn);
  3483.       emit_insn_before (gen_move_insn (tem, x), insn);
  3484.       return tem;
  3485.     }
  3486.       break;
  3487.  
  3488.     case REG:
  3489.     case CC0:
  3490.     case PC:
  3491.     case CONST_INT:
  3492.     case CONST:
  3493.     case SYMBOL_REF:
  3494.     case LABEL_REF:
  3495.     case CONST_DOUBLE:
  3496.       return x;
  3497.  
  3498.     case SIGN_EXTRACT:
  3499.     case ZERO_EXTRACT:
  3500.       /* Note that in some cases those types of expressions are altered
  3501.      by optimize_bit_field, and do not survive to get here.  */
  3502.     case SUBREG:
  3503.       tem = x;
  3504.       while (GET_CODE (tem) == SUBREG || GET_CODE (tem) == SIGN_EXTRACT
  3505.          || GET_CODE (tem) == ZERO_EXTRACT)
  3506.     tem = XEXP (tem, 0);
  3507.       if (tem == var)
  3508.     {
  3509.       x = fixup_stack_1 (x, insn);
  3510.       tem = gen_reg_rtx (GET_MODE (x));
  3511.       if (GET_CODE (x) == SUBREG)
  3512.         x = fixup_memory_subreg (x, insn);
  3513.       emit_insn_before (gen_move_insn (tem, x), insn);
  3514.       return tem;
  3515.     }
  3516.       break;
  3517.  
  3518.     case SET:
  3519.       /* First do special simplification of bit-field references.  */
  3520.       if (GET_CODE (SET_DEST (x)) == SIGN_EXTRACT
  3521.       || GET_CODE (SET_DEST (x)) == ZERO_EXTRACT)
  3522.     optimize_bit_field (x, insn, 0);
  3523.       if (GET_CODE (SET_SRC (x)) == SIGN_EXTRACT
  3524.       || GET_CODE (SET_SRC (x)) == ZERO_EXTRACT)
  3525.     optimize_bit_field (x, insn, 0);
  3526.  
  3527.       {
  3528.     rtx dest = SET_DEST (x);
  3529.     rtx src = SET_SRC (x);
  3530.     rtx outerdest = dest;
  3531.     rtx outersrc = src;
  3532.  
  3533.     while (GET_CODE (dest) == SUBREG || GET_CODE (dest) == STRICT_LOW_PART
  3534.            || GET_CODE (dest) == SIGN_EXTRACT
  3535.            || GET_CODE (dest) == ZERO_EXTRACT)
  3536.       dest = XEXP (dest, 0);
  3537.     while (GET_CODE (src) == SUBREG
  3538.            || GET_CODE (src) == SIGN_EXTRACT
  3539.            || GET_CODE (src) == ZERO_EXTRACT)
  3540.       src = XEXP (src, 0);
  3541.  
  3542.     /* If VAR does not appear at the top level of the SET
  3543.        just scan the lower levels of the tree.  */
  3544.  
  3545.         if (src != var && dest != var)
  3546.       break;
  3547.  
  3548.     /* Clean up (SUBREG:SI (MEM:mode ...) 0)
  3549.        that may appear inside a SIGN_EXTRACT or ZERO_EXTRACT.
  3550.        This was legitimate when the MEM was a REG.  */
  3551.  
  3552.     if ((GET_CODE (outerdest) == SIGN_EXTRACT
  3553.          || GET_CODE (outerdest) == ZERO_EXTRACT)
  3554.         && GET_CODE (XEXP (outerdest, 0)) == SUBREG
  3555.         && SUBREG_REG (XEXP (outerdest, 0)) == var)
  3556.       XEXP (outerdest, 0) = fixup_memory_subreg (XEXP (outerdest, 0), insn);
  3557.  
  3558.     if ((GET_CODE (outersrc) == SIGN_EXTRACT
  3559.          || GET_CODE (outersrc) == ZERO_EXTRACT)
  3560.         && GET_CODE (XEXP (outersrc, 0)) == SUBREG
  3561.         && SUBREG_REG (XEXP (outersrc, 0)) == var)
  3562.       XEXP (outersrc, 0) = fixup_memory_subreg (XEXP (outersrc, 0), insn);
  3563.  
  3564.     /* Make sure that the machine's SIGN_EXTRACT and ZERO_EXTRACT insns
  3565.        accept a memory operand.  */
  3566. #ifdef HAVE_extzv
  3567.     if (GET_CODE (outersrc) == ZERO_EXTRACT
  3568.         && ! ((*insn_operand_predicate[(int) CODE_FOR_extzv][0])
  3569.           (XEXP (outersrc, 0), VOIDmode)))
  3570.       XEXP (outersrc, 0) = src
  3571.         = fixup_var_refs_1 (var, XEXP (outersrc, 0), insn);
  3572. #endif
  3573. #ifdef HAVE_extv
  3574.     if (GET_CODE (outersrc) == SIGN_EXTRACT
  3575.         && ! ((*insn_operand_predicate[(int) CODE_FOR_extv][0])
  3576.           (XEXP (outersrc, 0), VOIDmode)))
  3577.       XEXP (outersrc, 0) = src
  3578.         = fixup_var_refs_1 (var, XEXP (outersrc, 0), insn);
  3579. #endif
  3580. #ifdef HAVE_insv
  3581.     if (GET_CODE (outerdest) == ZERO_EXTRACT
  3582.         && ! ((*insn_operand_predicate[(int) CODE_FOR_insv][0])
  3583.           (XEXP (outerdest, 0), VOIDmode)))
  3584.       {
  3585.         rtx tem = gen_reg_rtx (GET_MODE (XEXP (outerdest, 0)));
  3586.  
  3587.         emit_insn_before (gen_move_insn (tem, XEXP (outerdest, 0)), insn);
  3588.         emit_insn_after (gen_move_insn (XEXP (outerdest, 0), tem), insn);
  3589.         dest = XEXP (outerdest, 0) = tem;
  3590.       }
  3591. #endif
  3592.  
  3593.     /* Make sure a MEM inside a SIGN_EXTRACT has QImode
  3594.        since that's what bit-field insns want.  */
  3595.  
  3596.     if ((GET_CODE (outerdest) == SIGN_EXTRACT
  3597.          || GET_CODE (outerdest) == ZERO_EXTRACT)
  3598.         && GET_CODE (XEXP (outerdest, 0)) == MEM
  3599.         && GET_MODE (XEXP (outerdest, 0)) != QImode)
  3600.       {
  3601.         XEXP (outerdest, 0) = copy_rtx (XEXP (outerdest, 0));
  3602.         PUT_MODE (XEXP (outerdest, 0), QImode);
  3603.         /* Adjust the address so the bit field starts within the byte
  3604.            addressed.  This helps certain optimization patterns.  */
  3605.         if (GET_CODE (XEXP (outerdest, 2)) == CONST_INT
  3606.         && offsettable_memref_p (XEXP (outerdest, 0)))
  3607.           {
  3608.         int count = INTVAL (XEXP (outerdest, 2));
  3609.         XEXP (outerdest, 0)
  3610.           = adj_offsettable_operand (XEXP (outerdest, 0),
  3611.                          count / GET_MODE_BITSIZE (QImode));
  3612.         XEXP (outerdest, 2)
  3613.           = gen_rtx (CONST_INT, VOIDmode,
  3614.                  count % GET_MODE_BITSIZE (QImode));
  3615.           }
  3616.       }
  3617.  
  3618.     if ((GET_CODE (outersrc) == SIGN_EXTRACT
  3619.          || GET_CODE (outersrc) == ZERO_EXTRACT)
  3620.         && GET_CODE (XEXP (outersrc, 0)) == MEM
  3621.         && GET_MODE (XEXP (outersrc, 0)) != QImode)
  3622.       {
  3623.         XEXP (outersrc, 0) = copy_rtx (XEXP (outersrc, 0));
  3624.         PUT_MODE (XEXP (outersrc, 0), QImode);
  3625.         /* Adjust the address so the bit field starts within the byte
  3626.            addressed.  This helps certain optimization patterns.  */
  3627.         if (GET_CODE (XEXP (outersrc, 2)) == CONST_INT
  3628.         && offsettable_memref_p (XEXP (outersrc, 0)))
  3629.           {
  3630.         int count = INTVAL (XEXP (outersrc, 2));
  3631.         XEXP (outersrc, 0)
  3632.           = adj_offsettable_operand (XEXP (outersrc, 0),
  3633.                          count / GET_MODE_BITSIZE (QImode));
  3634.         XEXP (outersrc, 2)
  3635.           = gen_rtx (CONST_INT, VOIDmode,
  3636.                  count % GET_MODE_BITSIZE (QImode));
  3637.           }
  3638.       }
  3639.  
  3640.     /* STRICT_LOW_PART is a no-op on memory references
  3641.        and it can cause combinations to be unrecognizable,
  3642.        so eliminate it.  */
  3643.  
  3644.     if (dest == var && GET_CODE (SET_DEST (x)) == STRICT_LOW_PART)
  3645.       SET_DEST (x) = XEXP (SET_DEST (x), 0);
  3646.  
  3647.     /* An insn to copy VAR into or out of a register
  3648.        must be left alone, to avoid an infinite loop here.
  3649.        But do fix up the address of VAR's stack slot if nec,
  3650.        and fix up SUBREGs containing VAR
  3651.        (since they are now memory subregs).  */
  3652.  
  3653.     if (GET_CODE (SET_SRC (x)) == REG || GET_CODE (SET_DEST (x)) == REG
  3654.         || (GET_CODE (SET_SRC (x)) == SUBREG
  3655.         && GET_CODE (SUBREG_REG (SET_SRC (x))) == REG)
  3656.         || (GET_CODE (SET_DEST (x)) == SUBREG
  3657.         && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG))
  3658.       {
  3659.         if (src == var && GET_CODE (SET_SRC (x)) == SUBREG)
  3660.           SET_SRC (x) = fixup_memory_subreg (SET_SRC (x), insn);
  3661.         if (dest == var && GET_CODE (SET_DEST (x)) == SUBREG)
  3662.           SET_DEST (x) = fixup_memory_subreg (SET_DEST (x), insn);
  3663.         return fixup_stack_1 (x, insn);
  3664.       }
  3665.  
  3666.     /* Otherwise, storing into VAR must be handled specially
  3667.        by storing into a temporary and copying that into VAR
  3668.        with a new insn after this one.  */
  3669.  
  3670.     if (dest == var)
  3671.       {
  3672.         rtx temp;
  3673.         rtx fixeddest;
  3674.         tem = SET_DEST (x);
  3675.         /* STRICT_LOW_PART can be discarded, around a MEM.  */
  3676.         if (GET_CODE (tem) == STRICT_LOW_PART)
  3677.           tem = XEXP (tem, 0);
  3678.         /* Convert (SUBREG (MEM)) to a MEM in a changed mode.  */
  3679.         if (GET_CODE (tem) == SUBREG)
  3680.           tem = fixup_memory_subreg (tem, insn);
  3681.         fixeddest = fixup_stack_1 (tem, insn);
  3682.         temp = gen_reg_rtx (GET_MODE (tem));
  3683.         emit_insn_after (gen_move_insn (fixeddest, temp), insn);
  3684.         SET_DEST (x) = temp;
  3685.       }
  3686.       }
  3687.     }
  3688.  
  3689.   /* Nothing special about this RTX; fix its operands.  */
  3690.  
  3691.   fmt = GET_RTX_FORMAT (code);
  3692.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  3693.     {
  3694.       if (fmt[i] == 'e')
  3695.     XEXP (x, i) = fixup_var_refs_1 (var, XEXP (x, i), insn);
  3696.       if (fmt[i] == 'E')
  3697.     {
  3698.       register int j;
  3699.       for (j = 0; j < XVECLEN (x, i); j++)
  3700.         XVECEXP (x, i, j)
  3701.           = fixup_var_refs_1 (var, XVECEXP (x, i, j), insn);
  3702.     }
  3703.     }
  3704.   return x;
  3705. }
  3706.  
  3707. /* Given X, an rtx of the form (SUBREG:m1 (MEM:m2 addr)),
  3708.    return an rtx (MEM:m1 newaddr) which is equivalent.
  3709.    If any insns must be emitted to compute NEWADDR, put them before INSN.  */
  3710.  
  3711. static rtx
  3712. fixup_memory_subreg (x, insn)
  3713.      rtx x;
  3714.      rtx insn;
  3715. {
  3716.   int offset = SUBREG_WORD (x) * UNITS_PER_WORD;
  3717.   rtx addr = XEXP (SUBREG_REG (x), 0);
  3718.   enum machine_mode mode = GET_MODE (x);
  3719.   rtx saved, result;
  3720.  
  3721. #ifdef BYTES_BIG_ENDIAN
  3722.   offset += (MIN (UNITS_PER_WORD, GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))
  3723.          - MIN (UNITS_PER_WORD, GET_MODE_SIZE (mode)));
  3724. #endif
  3725.   addr = plus_constant (addr, offset);
  3726.   if (memory_address_p (mode, addr))
  3727.     return change_address (SUBREG_REG (x), mode, addr);
  3728.   saved = start_sequence ();
  3729.   result = change_address (SUBREG_REG (x), mode, addr);
  3730.   emit_insn_before (gen_sequence (), insn);
  3731.   end_sequence (saved);
  3732.   return result;
  3733. }
  3734.  
  3735. /* Do fixup_memory_subreg on all (SUBREG (MEM ...) ...) contained in X.
  3736.    Replace subexpressions of X in place.
  3737.    If X itself is a (SUBREG (MEM ...) ...), return the replacement expression.
  3738.    Otherwise return X, with its contents possibly altered.
  3739.  
  3740.    If any insns must be emitted to compute NEWADDR, put them before INSN.  */
  3741.  
  3742. static rtx
  3743. walk_fixup_memory_subreg (x, insn)
  3744.      register rtx x;
  3745.      rtx insn;
  3746. {
  3747.   register enum rtx_code code;
  3748.   register char *fmt;
  3749.   register int i;
  3750.  
  3751.   if (x == 0)
  3752.     return 0;
  3753.  
  3754.   code = GET_CODE (x);
  3755.  
  3756.   if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == MEM)
  3757.     return fixup_memory_subreg (x, insn);
  3758.  
  3759.   /* Nothing special about this RTX; fix its operands.  */
  3760.  
  3761.   fmt = GET_RTX_FORMAT (code);
  3762.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  3763.     {
  3764.       if (fmt[i] == 'e')
  3765.     XEXP (x, i) = walk_fixup_memory_subreg (XEXP (x, i), insn);
  3766.       if (fmt[i] == 'E')
  3767.     {
  3768.       register int j;
  3769.       for (j = 0; j < XVECLEN (x, i); j++)
  3770.         XVECEXP (x, i, j)
  3771.           = walk_fixup_memory_subreg (XVECEXP (x, i, j), insn);
  3772.     }
  3773.     }
  3774.   return x;
  3775. }
  3776.  
  3777. #if 0
  3778. /* Fix up any references to stack slots that are invalid memory addresses
  3779.    because they exceed the maximum range of a displacement.  */
  3780.  
  3781. void
  3782. fixup_stack_slots ()
  3783. {
  3784.   register rtx insn;
  3785.  
  3786.   /* Did we generate a stack slot that is out of range
  3787.      or otherwise has an invalid address?  */
  3788.   if (invalid_stack_slot)
  3789.     {
  3790.       /* Yes.  Must scan all insns for stack-refs that exceed the limit.  */
  3791.       for (insn = get_insns (); insn; insn = NEXT_INSN (insn))
  3792.     if (GET_CODE (insn) == INSN || GET_CODE (insn) == CALL_INSN
  3793.         || GET_CODE (insn) == JUMP_INSN)
  3794.       fixup_stack_1 (PATTERN (insn), insn);
  3795.     }
  3796. }
  3797. #endif
  3798.  
  3799. /* For each memory ref within X, if it refers to a stack slot
  3800.    with an out of range displacement, put the address in a temp register
  3801.    (emitting new insns before INSN to load these registers)
  3802.    and alter the memory ref to use that register.
  3803.    Replace each such MEM rtx with a copy, to avoid clobberage.  */
  3804.  
  3805. static rtx
  3806. fixup_stack_1 (x, insn)
  3807.      rtx x;
  3808.      rtx insn;
  3809. {
  3810.   register int i;
  3811.   register RTX_CODE code = GET_CODE (x);
  3812.   register char *fmt;
  3813.  
  3814.   if (code == MEM)
  3815.     {
  3816.       register rtx ad = XEXP (x, 0);
  3817.       /* If we have address of a stack slot but it's not valid
  3818.      (displacement is too large), compute the sum in a register.  */
  3819.       if (GET_CODE (ad) == PLUS
  3820.       && XEXP (ad, 0) == frame_pointer_rtx
  3821.       && GET_CODE (XEXP (ad, 1)) == CONST_INT)
  3822.     {
  3823.       rtx temp;
  3824.       if (memory_address_p (GET_MODE (x), ad))
  3825.         return x;
  3826.       temp = gen_reg_rtx (GET_MODE (ad));
  3827.       emit_insn_before (gen_move_insn (temp, ad), insn);
  3828.       return change_address (x, VOIDmode, temp);
  3829.     }
  3830.       return x;
  3831.     }
  3832.  
  3833.   fmt = GET_RTX_FORMAT (code);
  3834.   for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--)
  3835.     {
  3836.       if (fmt[i] == 'e')
  3837.     XEXP (x, i) = fixup_stack_1 (XEXP (x, i), insn);
  3838.       if (fmt[i] == 'E')
  3839.     {
  3840.       register int j;
  3841.       for (j = 0; j < XVECLEN (x, i); j++)
  3842.         XVECEXP (x, i, j) = fixup_stack_1 (XVECEXP (x, i, j), insn);
  3843.     }
  3844.     }
  3845.   return x;
  3846. }
  3847.  
  3848. /* Optimization: a bit-field instruction whose field
  3849.    happens to be a byte or halfword in memory
  3850.    can be changed to a move instruction.
  3851.  
  3852.    We call here when INSN is an insn to examine or store into a bit-field.
  3853.    BODY is the SET-rtx to be altered.
  3854.  
  3855.    EQUIV_MEM is the table `reg_equiv_mem' if that is available; else 0.
  3856.    (Currently this is called only from stmt.c, and EQUIV_MEM is always 0.)  */
  3857.  
  3858. static void
  3859. optimize_bit_field (body, insn, equiv_mem)
  3860.      rtx body;
  3861.      rtx insn;
  3862.      rtx *equiv_mem;
  3863. {
  3864.   register rtx bitfield;
  3865.   int destflag;
  3866.  
  3867.   if (GET_CODE (SET_DEST (body)) == SIGN_EXTRACT
  3868.       || GET_CODE (SET_DEST (body)) == ZERO_EXTRACT)
  3869.     bitfield = SET_DEST (body), destflag = 1;
  3870.   else
  3871.     bitfield = SET_SRC (body), destflag = 0;
  3872.  
  3873.   /* First check that the field being stored has constant size and position
  3874.      and is in fact a byte or halfword suitably aligned.  */
  3875.  
  3876.   if (GET_CODE (XEXP (bitfield, 1)) == CONST_INT
  3877.       && GET_CODE (XEXP (bitfield, 2)) == CONST_INT
  3878.       && (INTVAL (XEXP (bitfield, 1)) == GET_MODE_BITSIZE (QImode)
  3879.       || INTVAL (XEXP (bitfield, 1)) == GET_MODE_BITSIZE (HImode))
  3880.       && INTVAL (XEXP (bitfield, 2)) % INTVAL (XEXP (bitfield, 1)) == 0)
  3881.     {
  3882.       register rtx memref = 0;
  3883.  
  3884.       /* Now check that the containing word is memory, not a register,
  3885.      and that it is safe to change the machine mode and to
  3886.      add something to the address.  */
  3887.  
  3888.       if (GET_CODE (XEXP (bitfield, 0)) == MEM)
  3889.     memref = XEXP (bitfield, 0);
  3890.       else if (GET_CODE (XEXP (bitfield, 0)) == REG
  3891.            && equiv_mem != 0)
  3892.     memref = equiv_mem[REGNO (XEXP (bitfield, 0))];
  3893.       else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
  3894.            && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == MEM)
  3895.     memref = SUBREG_REG (XEXP (bitfield, 0));
  3896.       else if (GET_CODE (XEXP (bitfield, 0)) == SUBREG
  3897.            && equiv_mem != 0
  3898.            && GET_CODE (SUBREG_REG (XEXP (bitfield, 0))) == REG)
  3899.     memref = equiv_mem[REGNO (SUBREG_REG (XEXP (bitfield, 0)))];
  3900.  
  3901.       if (memref
  3902.       && ! mode_dependent_address_p (XEXP (memref, 0))
  3903.       && offsettable_address_p (0, GET_MODE (bitfield), XEXP (memref, 0)))
  3904.     {
  3905.       /* Now adjust the address, first for any subreg'ing
  3906.          that we are now getting rid of,
  3907.          and then for which byte of the word is wanted.  */
  3908.  
  3909.       register int offset
  3910.         = INTVAL (XEXP (bitfield, 2)) / GET_MODE_BITSIZE (QImode);
  3911.       if (GET_CODE (XEXP (bitfield, 0)) == SUBREG)
  3912.         {
  3913.           offset += SUBREG_WORD (XEXP (bitfield, 0)) * UNITS_PER_WORD;
  3914. #ifdef BYTES_BIG_ENDIAN
  3915.           offset -= (MIN (UNITS_PER_WORD,
  3916.                   GET_MODE_SIZE (GET_MODE (XEXP (bitfield, 0))))
  3917.              - MIN (UNITS_PER_WORD,
  3918.                 GET_MODE_SIZE (GET_MODE (memref))));
  3919. #endif
  3920.         }
  3921.  
  3922.       memref = gen_rtx (MEM,
  3923.                 (INTVAL (XEXP (bitfield, 1)) == GET_MODE_BITSIZE (QImode)
  3924.                  ? QImode : HImode),
  3925.                 XEXP (memref, 0));
  3926.  
  3927.       /* Store this memory reference where
  3928.          we found the bit field reference.  */
  3929.  
  3930.       if (destflag)
  3931.         {
  3932.           SET_DEST (body)
  3933.         = adj_offsettable_operand (memref, offset);
  3934.           if (! CONSTANT_ADDRESS_P (SET_SRC (body)))
  3935.         {
  3936.           rtx src = SET_SRC (body);
  3937.           while (GET_CODE (src) == SUBREG
  3938.              && SUBREG_WORD (src) == 0)
  3939.             src = SUBREG_REG (src);
  3940.           if (GET_MODE (src) != GET_MODE (memref))
  3941.             src = gen_lowpart (GET_MODE (memref), SET_SRC (body));
  3942.           SET_SRC (body) = src;
  3943.         }
  3944.           else if (GET_MODE (SET_SRC (body)) != VOIDmode
  3945.                && GET_MODE (SET_SRC (body)) != GET_MODE (memref))
  3946.         /* This shouldn't happen because anything that didn't have
  3947.            one of these modes should have got converted explicitly
  3948.            and then referenced through a subreg.
  3949.            This is so because the original bit-field was
  3950.            handled by agg_mode and so its tree structure had
  3951.            the same mode that memref now has.  */
  3952.         abort ();
  3953.         }
  3954.       else
  3955.         {
  3956.           rtx dest = SET_DEST (body);
  3957.  
  3958.           while (GET_CODE (dest) == SUBREG
  3959.              && SUBREG_WORD (dest) == 0)
  3960.         dest = SUBREG_REG (dest);
  3961.           SET_DEST (body) = dest;
  3962.  
  3963.           memref = adj_offsettable_operand (memref, offset);
  3964.           if (GET_MODE (dest) == GET_MODE (memref))
  3965.         SET_SRC (body) = memref;
  3966.           else
  3967.         {
  3968.           /* Convert the mem ref to the destination mode.  */
  3969.           rtx last = get_last_insn ();
  3970.           rtx newreg = gen_reg_rtx (GET_MODE (dest));
  3971.           convert_move (newreg, memref,
  3972.                 GET_CODE (SET_SRC (body)) == ZERO_EXTRACT);
  3973.           /* Put the conversion before the insn being fixed.  */
  3974.           reorder_insns (NEXT_INSN (last), get_last_insn (),
  3975.                  PREV_INSN (insn));
  3976.           SET_SRC (body) = newreg;
  3977.         }
  3978.         }
  3979.  
  3980.       /* Cause the insn to be re-recognized.  */
  3981.  
  3982.       INSN_CODE (insn) = -1;
  3983.     }
  3984.     }
  3985. }
  3986.  
  3987. /* 1 + last pseudo register number used for loading a copy
  3988.    of a parameter of this function.  */
  3989.  
  3990. static int max_parm_reg;
  3991.  
  3992. /* Vector indexed by REGNO, containing location on stack in which
  3993.    to put the parm which is nominally in pseudo register REGNO,
  3994.    if we discover that that parm must go in the stack.  */
  3995. static rtx *parm_reg_stack_loc;
  3996.  
  3997. int
  3998. max_parm_reg_num ()
  3999. {
  4000.   return max_parm_reg;
  4001. }
  4002.  
  4003. /* Return the first insn following those generated by `assign_parms'.  */
  4004.  
  4005. rtx
  4006. get_first_nonparm_insn ()
  4007. {
  4008.   if (last_parm_insn)
  4009.     return NEXT_INSN (last_parm_insn);
  4010.   return get_insns ();
  4011. }
  4012.  
  4013. /* Get the stack home of a REG rtx that is one of this function's parameters.
  4014.    This is called rather than assign a new stack slot as a local.
  4015.    Return 0 if there is no existing stack home suitable for such use.  */
  4016.  
  4017. static rtx
  4018. parm_stack_loc (reg)
  4019.      rtx reg;
  4020. {
  4021.   if (REGNO (reg) < max_parm_reg)
  4022.     return parm_reg_stack_loc[REGNO (reg)];
  4023.   return 0;
  4024. }
  4025.  
  4026. /* Return 1 if EXP returns an aggregate value, for which an address
  4027.    must be passed to the function or returned by the function.  */
  4028.  
  4029. int
  4030. aggregate_value_p (exp)
  4031.      tree exp;
  4032. {
  4033.   if (TYPE_MODE (TREE_TYPE (exp)) == BLKmode)
  4034.     return 1;
  4035.   if (RETURN_IN_MEMORY (TREE_TYPE (exp)))
  4036.     return 1;
  4037.   if (flag_pcc_struct_return
  4038.       && (TREE_CODE (TREE_TYPE (exp)) == RECORD_TYPE
  4039.       || TREE_CODE (TREE_TYPE (exp)) == UNION_TYPE))
  4040.     return 1;
  4041.   return 0;
  4042. }
  4043.  
  4044. /* Convert a mem ref into one with a valid memory address.
  4045.    Pass through anything else unchanged.  */
  4046.  
  4047. rtx
  4048. validize_mem (ref)
  4049.      rtx ref;
  4050. {
  4051.   if (GET_CODE (ref) != MEM)
  4052.     return ref;
  4053.   if (memory_address_p (GET_MODE (ref), XEXP (ref, 0)))
  4054.     return ref;
  4055.   return change_address (ref, VOIDmode,
  4056.              memory_address (GET_MODE (ref), XEXP (ref, 0)));
  4057. }
  4058.  
  4059. /* Assign RTL expressions to the function's parameters.
  4060.    This may involve copying them into registers and using
  4061.    those registers as the RTL for them.  */
  4062.  
  4063. static void
  4064. assign_parms (fndecl)
  4065.      tree fndecl;
  4066. {
  4067.   register tree parm;
  4068.   register rtx entry_parm;
  4069.   register rtx stack_parm;
  4070.   register CUMULATIVE_ARGS args_so_far;
  4071.   enum machine_mode passed_mode, nominal_mode;
  4072.   /* Total space needed so far for args on the stack,
  4073.      given as a constant and a tree-expression.  */
  4074.   struct args_size stack_args_size;
  4075.   int first_parm_offset = FIRST_PARM_OFFSET (fndecl);
  4076.   tree fntype = TREE_TYPE (fndecl);
  4077.   /* This is used for the arg pointer when referring to stack args.  */
  4078.   rtx internal_arg_pointer;
  4079.  
  4080.   int nparmregs
  4081.     = list_length (DECL_ARGUMENTS (fndecl)) + FIRST_PSEUDO_REGISTER;
  4082.  
  4083.   /* Nonzero if function takes extra anonymous args.
  4084.      This means the last named arg must be on the stack
  4085.      right before the anonymous ones.
  4086.      Also nonzero if the first arg is named `__builtin_va_alist',
  4087.      which is used on some machines for old-fashioned non-ANSI varargs.h;
  4088.      this too should be stuck onto the stack as if it had arrived there.  */
  4089.   int vararg
  4090.     = ((DECL_ARGUMENTS (fndecl) != 0
  4091.     && DECL_NAME (DECL_ARGUMENTS (fndecl))
  4092.     && (! strcmp (IDENTIFIER_POINTER (DECL_NAME (DECL_ARGUMENTS (fndecl))),
  4093.               "__builtin_va_alist")))
  4094.        ||
  4095.        (TYPE_ARG_TYPES (fntype) != 0
  4096.     && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (fntype)))
  4097.         != void_type_node)));
  4098.   int arg_pointer_copied = 0;
  4099.  
  4100. #if ARG_POINTER_REGNUM == FRAME_POINTER_REGNUM
  4101.   internal_arg_pointer = arg_pointer_rtx;
  4102. #else
  4103.   /* If the arg pointer reg is not a fixed reg,
  4104.      make a copy of it, and address parms via the copy.  */
  4105.   if (fixed_regs[ARG_POINTER_REGNUM])
  4106.     internal_arg_pointer = arg_pointer_rtx;
  4107.   else
  4108.     {
  4109.       internal_arg_pointer = copy_to_reg (arg_pointer_rtx);
  4110.       arg_pointer_copied = 1;
  4111.     }
  4112. #endif
  4113.  
  4114.   stack_args_size.constant = 0;
  4115.   stack_args_size.var = 0;
  4116.  
  4117.   /* If struct value address comes on the stack, count it in size of args.  */
  4118.   if (aggregate_value_p (DECL_RESULT (fndecl))
  4119.       && GET_CODE (struct_value_incoming_rtx) == MEM)
  4120.     stack_args_size.constant += GET_MODE_SIZE (Pmode);
  4121.  
  4122.   parm_reg_stack_loc = (rtx *) oballoc (nparmregs * sizeof (rtx));
  4123.   bzero (parm_reg_stack_loc, nparmregs * sizeof (rtx));
  4124.  
  4125.   INIT_CUMULATIVE_ARGS (args_so_far, fntype);
  4126.  
  4127.   for (parm = DECL_ARGUMENTS (fndecl); parm; parm = TREE_CHAIN (parm))
  4128.     {
  4129.       int aggregate
  4130.     = (TREE_CODE (TREE_TYPE (parm)) == ARRAY_TYPE
  4131.        || TREE_CODE (TREE_TYPE (parm)) == RECORD_TYPE
  4132.        || TREE_CODE (TREE_TYPE (parm)) == UNION_TYPE);
  4133.       struct args_size stack_offset;
  4134.       rtx stack_offset_rtx;
  4135.       enum direction where_pad;
  4136.       /* Extra bytes to add in after parameter is assigned, in
  4137.      case where argument cannot be assigned an offsetted
  4138.      location.  For example, BLKmode parameters cannot be
  4139.      other than on a word boundary (no matter the size)
  4140.      because `access_parm_map' does not know how to handle
  4141.      that case.  */
  4142.       int extra = 0;
  4143.  
  4144.       DECL_OFFSET (parm) = -1;
  4145.  
  4146.       if (TREE_TYPE (parm) == error_mark_node
  4147.       /* This can happen after weird syntax errors
  4148.          or if an enum type is defined among the parms.  */
  4149.       || TREE_CODE (parm) != PARM_DECL
  4150.       || DECL_ARG_TYPE (parm) == NULL)
  4151.     {
  4152.       DECL_RTL (parm) = gen_rtx (MEM, BLKmode, const0_rtx);
  4153.       TREE_USED (parm) = 1;
  4154.       continue;
  4155.     }
  4156.  
  4157.       /* Find mode of arg as it is passed, and mode of arg
  4158.      as it should be during execution of this function.  */
  4159.       passed_mode = TYPE_MODE (DECL_ARG_TYPE (parm));
  4160.       nominal_mode = TYPE_MODE (TREE_TYPE (parm));
  4161.  
  4162.       /* Get this parm's offset as an rtx.  */
  4163.       stack_offset = stack_args_size;
  4164.       stack_offset.constant += first_parm_offset;
  4165.  
  4166.       /* If this argument needs more than the usual parm alignment, do
  4167.      extrinsic padding to reach that alignment.  */
  4168.  
  4169. #ifdef MAX_PARM_BOUNDARY
  4170.       /* If MAX_PARM_BOUNDARY is not defined, it means that the usual
  4171.      alignment requirements are relaxed for parms, and that no parm
  4172.      needs more alignment than PARM_BOUNDARY, regardless of data type.  */
  4173.  
  4174.       if (PARM_BOUNDARY < TYPE_ALIGN (DECL_ARG_TYPE (parm)))
  4175.     {
  4176.       int boundary = PARM_BOUNDARY;
  4177.  
  4178.       /* Determine the boundary to pad up to.  */
  4179.       if (TYPE_ALIGN (DECL_ARG_TYPE (parm)) > boundary)
  4180.         boundary = TYPE_ALIGN (DECL_ARG_TYPE (parm));
  4181.       if (boundary > MAX_PARM_BOUNDARY)
  4182.         boundary = MAX_PARM_BOUNDARY;
  4183.  
  4184.       /* If the previous args don't reach such a boundary,
  4185.          advance to the next one.  */
  4186.       boundary /= BITS_PER_UNIT;
  4187.       stack_offset.constant += boundary - 1;
  4188.       stack_offset.constant &= ~(boundary - 1);
  4189.       stack_args_size.constant += boundary - 1;
  4190.       stack_args_size.constant &= ~(boundary - 1);
  4191.  
  4192.       if (stack_offset.var != 0)
  4193.         abort ();        /* This case not implemented yet */
  4194.     }
  4195. #endif /* MAX_PARM_BOUNDARY */
  4196.  
  4197.       /* Find out if the parm needs intrinsic padding (up to PARM_BOUNDARY),
  4198.      and whether above or below.  */
  4199.  
  4200.       where_pad
  4201.     = FUNCTION_ARG_PADDING (passed_mode,
  4202.                 expand_expr (size_in_bytes (DECL_ARG_TYPE (parm)),
  4203.                          0, VOIDmode, 0));
  4204.  
  4205.       /* If arg should be padded below, adjust the stack address upward.
  4206.      This padding is considered part of the space occupied by the
  4207.      argument.  It pads only up to PARM_BOUNDARY, and it does not
  4208.      depend on the previous arguments, since they are assumed to
  4209.      occupy a multiple of PARM_BOUNDARY.  */
  4210.  
  4211.       if (where_pad == downward)
  4212.     {
  4213.       if (passed_mode != BLKmode)
  4214.         {
  4215.           if (GET_MODE_BITSIZE (passed_mode) % PARM_BOUNDARY)
  4216.         stack_offset.constant
  4217.           += (((GET_MODE_BITSIZE (passed_mode) + PARM_BOUNDARY - 1)
  4218.                / PARM_BOUNDARY * PARM_BOUNDARY / BITS_PER_UNIT)
  4219.               - GET_MODE_SIZE (passed_mode));
  4220.         }
  4221.       else
  4222.         {
  4223.           tree sizetree = size_in_bytes (DECL_ARG_TYPE (parm));
  4224.           if (TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT != PARM_BOUNDARY)
  4225.         {
  4226.           /* Round the size up to multiple of PARM_BOUNDARY bits.  */
  4227.           tree s1 = convert_units (sizetree, BITS_PER_UNIT, PARM_BOUNDARY);
  4228.           tree s2 = convert_units (s1, PARM_BOUNDARY, BITS_PER_UNIT);
  4229.           /* Add it in.  */
  4230.           ADD_PARM_SIZE (stack_offset, s2);
  4231.           SUB_PARM_SIZE (stack_offset, sizetree);
  4232.           extra = stack_offset.constant % UNITS_PER_WORD;
  4233.           stack_offset.constant -= extra;
  4234.         }
  4235.         }
  4236.     }
  4237.  
  4238.       stack_offset_rtx = ARGS_SIZE_RTX (stack_offset);
  4239.  
  4240.       /* Determine parm's home in the stack,
  4241.      in case it arrives in the stack or we should pretend it did.  */
  4242.       stack_parm
  4243.     = gen_rtx (MEM, passed_mode,
  4244.            memory_address (passed_mode,
  4245.                    gen_rtx (PLUS, Pmode,
  4246.                         internal_arg_pointer,
  4247.                         stack_offset_rtx)));
  4248.  
  4249.       /* If this is a memory ref that contains aggregate components,
  4250.      mark it as such for cse and loop optimize.  */
  4251.       MEM_IN_STRUCT_P (stack_parm) = aggregate;
  4252.  
  4253.       /* Let machine desc say which reg (if any) the parm arrives in.
  4254.      0 means it arrives on the stack.  */
  4255.       entry_parm = 0;
  4256.       /* Variable-size args, and args following such, are never in regs.  */
  4257.       if (TREE_CODE (TYPE_SIZE (TREE_TYPE (parm))) == INTEGER_CST
  4258.       || stack_offset.var != 0)
  4259.     {
  4260.       /* Set LAST_NAMED if this is last named arg before some
  4261.          anonymous args.  We treat it as if it were anonymous too.  */
  4262.       int last_named = (TREE_CHAIN (parm) == 0 && vararg);
  4263. #ifdef FUNCTION_INCOMING_ARG
  4264.       entry_parm
  4265.         = FUNCTION_INCOMING_ARG (args_so_far, passed_mode,
  4266.                      DECL_ARG_TYPE (parm), ! last_named);
  4267. #else
  4268.       entry_parm
  4269.         = FUNCTION_ARG (args_so_far, passed_mode, DECL_ARG_TYPE (parm),
  4270.                 ! last_named);
  4271. #endif
  4272.     }
  4273.  
  4274.       /* If this parm was passed part in regs and part in memory,
  4275.      pretend it arrived entirely in memory
  4276.      by pushing the register-part onto the stack.
  4277.  
  4278.      In the special case of a DImode or DFmode that is split,
  4279.      we could put it together in a pseudoreg directly,
  4280.      but for now that's not worth bothering with.  */
  4281.  
  4282.       if (entry_parm)
  4283.     {
  4284.       int nregs = 0;
  4285.       int i;
  4286. #ifdef FUNCTION_ARG_PARTIAL_NREGS
  4287.       nregs = FUNCTION_ARG_PARTIAL_NREGS (args_so_far, passed_mode,
  4288.                           DECL_ARG_TYPE (parm), 1);
  4289. #endif
  4290.  
  4291. #if 0 /* Replaced by new calling convention
  4292.      which actually passes these args on the stack.  */
  4293.       /* If this is the last named arg and anonymous args follow,
  4294.          likewise pretend this arg arrived on the stack
  4295.          so varargs can find the anonymous args following it.  */
  4296.       if (TREE_CHAIN (parm) == 0 && vararg)
  4297.         {
  4298.           if (GET_MODE (entry_parm) == BLKmode)
  4299.         nregs = GET_MODE_SIZE (GET_MODE (entry_parm)) / UNITS_PER_WORD;
  4300.           else
  4301.         nregs = (int_size_in_bytes (DECL_ARG_TYPE (parm))
  4302.              / UNITS_PER_WORD);
  4303.         }
  4304. #endif /* 0 */
  4305.  
  4306.       if (nregs > 0)
  4307.         {
  4308.           current_function_pretend_args_size
  4309.         = (((nregs * UNITS_PER_WORD) + (PARM_BOUNDARY / BITS_PER_UNIT) - 1)
  4310.            / (PARM_BOUNDARY / BITS_PER_UNIT)
  4311.            * (PARM_BOUNDARY / BITS_PER_UNIT));
  4312.  
  4313.           i = nregs;
  4314.           while (--i >= 0)
  4315.         emit_move_insn (gen_rtx (MEM, SImode,
  4316.                      plus_constant (XEXP (stack_parm, 0),
  4317.                             i * GET_MODE_SIZE (SImode))),
  4318.                 gen_rtx (REG, SImode, REGNO (entry_parm) + i));
  4319.           entry_parm = stack_parm;
  4320.         }
  4321.     }
  4322.  
  4323.       /* If we didn't decide this parm came in a register,
  4324.      by default it came on the stack.  */
  4325.       if (entry_parm == 0)
  4326.     entry_parm = stack_parm;
  4327.  
  4328.       /* For a stack parm, record in DECL_OFFSET the arglist offset
  4329.      of the parm at the time it is passed (before conversion).  */
  4330.       if (entry_parm == stack_parm)
  4331.     DECL_OFFSET (parm) = stack_offset.constant * BITS_PER_UNIT;
  4332.  
  4333.       /* If there is actually space on the stack for this parm,
  4334.      count it in stack_args_size; otherwise set stack_parm to 0
  4335.      to indicate there is no preallocated stack slot for the parm.  */
  4336.  
  4337.       if (entry_parm == stack_parm
  4338. #ifdef REG_PARM_STACK_SPACE
  4339.       /* On some machines, even if a parm value arrives in a register
  4340.          there is still an (uninitialized) stack slot allocated for it.  */
  4341.       || 1
  4342. #endif
  4343.       )
  4344.     {
  4345.       tree sizetree = size_in_bytes (DECL_ARG_TYPE (parm));
  4346.       if (where_pad != none
  4347.           && TREE_INT_CST_LOW (sizetree) * BITS_PER_UNIT != PARM_BOUNDARY)
  4348.         {
  4349.           /* Round the size up to multiple of PARM_BOUNDARY bits.  */
  4350.           tree s1 = convert_units (sizetree, BITS_PER_UNIT, PARM_BOUNDARY);
  4351.           sizetree = convert_units (s1, PARM_BOUNDARY, BITS_PER_UNIT);
  4352.         }
  4353.       /* Add it in.  */
  4354.       ADD_PARM_SIZE (stack_args_size, sizetree);
  4355.     }
  4356.       else
  4357.     /* No stack slot was pushed for this parm.  */
  4358.     stack_parm = 0;
  4359.  
  4360.       /* Now adjust STACK_PARM to the mode and precise location
  4361.      where this parameter should live during execution,
  4362.      if we discover that it must live in the stack during execution.
  4363.      To make debuggers happier on big-endian machines, we store
  4364.      the value in the last bytes of the space available.  */
  4365.  
  4366.       if (nominal_mode != BLKmode && nominal_mode != passed_mode
  4367.       && stack_parm != 0)
  4368.     {
  4369. #ifdef BYTES_BIG_ENDIAN
  4370.       if (GET_MODE_SIZE (nominal_mode) < UNITS_PER_WORD)
  4371.         {
  4372.           stack_offset.constant
  4373.         += GET_MODE_SIZE (passed_mode)
  4374.           - GET_MODE_SIZE (nominal_mode);
  4375.           stack_offset_rtx = ARGS_SIZE_RTX (stack_offset);
  4376.         }
  4377. #endif
  4378.  
  4379.       stack_parm
  4380.         = gen_rtx (MEM, nominal_mode,
  4381.                memory_address (nominal_mode,
  4382.                        gen_rtx (PLUS, Pmode,
  4383.                         arg_pointer_rtx,
  4384.                         stack_offset_rtx)));
  4385.  
  4386.       /* If this is a memory ref that contains aggregate components,
  4387.          mark it as such for cse and loop optimize.  */
  4388.       MEM_IN_STRUCT_P (stack_parm) = aggregate;
  4389.     }
  4390.  
  4391.       /* If there is rounding to do for a BLKmode parameter,
  4392.      add it in here, since STACK_OFFSET is not used for the
  4393.      rest of this iteration.  */
  4394.       stack_offset.constant += extra;
  4395.  
  4396.       /* ENTRY_PARM is an RTX for the parameter as it arrives,
  4397.      in the mode in which it arrives.
  4398.      STACK_PARM is an RTX for a stack slot where the parameter can live
  4399.      during the function (in case we want to put it there).
  4400.      STACK_PARM is 0 if no stack slot was pushed for it.
  4401.  
  4402.      Now output code if necessary to convert ENTRY_PARM to
  4403.      the type in which this function declares it,
  4404.      and store that result in an appropriate place,
  4405.      which may be a pseudo reg, may be STACK_PARM,
  4406.      or may be a local stack slot if STACK_PARM is 0.
  4407.  
  4408.      Set DECL_RTL to that place.  */
  4409.  
  4410.       if (nominal_mode == BLKmode)
  4411.     {
  4412.       /* If a BLKmode arrives in registers, copy it to a stack slot.  */
  4413.       if (GET_CODE (entry_parm) == REG)
  4414.         {
  4415.           if (stack_parm == 0)
  4416.         stack_parm
  4417.           = assign_stack_local (GET_MODE (entry_parm),
  4418.                     int_size_in_bytes (TREE_TYPE (parm)));
  4419.  
  4420.           move_block_from_reg (REGNO (entry_parm), stack_parm,
  4421.                    ((int_size_in_bytes (TREE_TYPE (parm))
  4422.                      + UNITS_PER_WORD - 1)
  4423.                     / UNITS_PER_WORD));
  4424.         }
  4425.       else if (vararg)
  4426.         {
  4427.           /* If this function uses varargs, and `__builtin_saveregs'
  4428.          can clobber this stack location, then protect it.  */
  4429.           rtx pseudo_parm;
  4430. #ifdef FUNCTION_INCOMING_ARG
  4431.           pseudo_parm
  4432.         = FUNCTION_INCOMING_ARG (args_so_far, SImode,
  4433.                      integer_type_node, 1);
  4434. #else
  4435.           pseudo_parm
  4436.         = FUNCTION_ARG (args_so_far, SImode,
  4437.                 integer_type_node, 1);
  4438. #endif
  4439.           if (pseudo_parm && GET_CODE (pseudo_parm) == REG)
  4440.         {
  4441.           push_to_sequence (save_from_saveregs);
  4442.           move_block_to_reg (REGNO (pseudo_parm), stack_parm,
  4443.                      int_size_in_bytes (TREE_TYPE (parm))
  4444.                      / UNITS_PER_WORD);
  4445.           save_from_saveregs = get_insns ();
  4446.           end_sequence (0);
  4447.         }
  4448.         }
  4449.       DECL_RTL (parm) = stack_parm;
  4450.     }
  4451.       else if (! ((obey_regdecls && ! TREE_REGDECL (parm)
  4452.            && ! TREE_INLINE (fndecl))
  4453.           /* layout_decl may set this.  */
  4454.           || TREE_ADDRESSABLE (parm)
  4455.           || TREE_VOLATILE (parm)
  4456.           /* If -ffloat-store specified, don't put explicit
  4457.              float variables into registers.  */
  4458.           || (flag_float_store
  4459.               && TREE_CODE (TREE_TYPE (parm)) == REAL_TYPE)))
  4460.     {
  4461.       /* Store the parm in a pseudoregister during the function.  */
  4462.       register rtx parmreg = gen_reg_rtx (nominal_mode);
  4463.  
  4464.       REG_USERVAR_P (parmreg) = 1;
  4465.       DECL_RTL (parm) = parmreg;
  4466.  
  4467.       /* Copy the value into the register.  */
  4468.       if (GET_MODE (parmreg) != GET_MODE (entry_parm))
  4469.         convert_move (parmreg, validize_mem (entry_parm), 0);
  4470.       else
  4471.         emit_move_insn (parmreg, validize_mem (entry_parm));
  4472.  
  4473.       /* In any case, record the parm's desired stack location
  4474.          in case we later discover it must live in the stack.  */
  4475.       if (REGNO (parmreg) >= nparmregs)
  4476.         {
  4477.           rtx *new;
  4478.           nparmregs = REGNO (parmreg) + 5;
  4479.           new = (rtx *) oballoc (nparmregs * sizeof (rtx));
  4480.           bcopy (parm_reg_stack_loc, new, nparmregs * sizeof (rtx));
  4481.           parm_reg_stack_loc = new;
  4482.         }
  4483.       parm_reg_stack_loc[REGNO (parmreg)] = stack_parm;
  4484.  
  4485.       /* Mark the register as eliminable if we did no conversion
  4486.          and it was copied from memory at a fixed offset,
  4487.          and the arg pointer was not copied to a pseudo-reg.
  4488.          If the arg pointer is a pseudo reg, such memory-equivalences
  4489.          as we make here would screw up life analysis for it.  */
  4490.       if (nominal_mode == passed_mode
  4491.           && GET_CODE (entry_parm) == MEM
  4492.           && stack_offset.var == 0
  4493.           && ! arg_pointer_copied)
  4494.         REG_NOTES (get_last_insn ())
  4495.           = gen_rtx (EXPR_LIST, REG_EQUIV,
  4496.              entry_parm, REG_NOTES (get_last_insn ()));
  4497.  
  4498.       /* For pointer data type, suggest pointer register.  */
  4499.       if (TREE_CODE (TREE_TYPE (parm)) == POINTER_TYPE)
  4500.         mark_reg_pointer (parmreg);
  4501.     }
  4502.       else
  4503.     {
  4504.       /* Value must be stored in the stack slot STACK_PARM
  4505.          during function execution.  */
  4506.  
  4507.       if (passed_mode != nominal_mode)
  4508.         /* Conversion is required.  */
  4509.         entry_parm = convert_to_mode (nominal_mode, entry_parm, 0);
  4510.  
  4511.       if (entry_parm != stack_parm)
  4512.         {
  4513.           if (stack_parm == 0)
  4514.         stack_parm = assign_stack_local (GET_MODE (entry_parm),
  4515.                          GET_MODE_SIZE (GET_MODE (entry_parm)));
  4516.           emit_move_insn (validize_mem (stack_parm),
  4517.                   validize_mem (entry_parm));
  4518.         }
  4519.  
  4520.       DECL_RTL (parm) = stack_parm;
  4521.       frame_pointer_needed = 1;
  4522.     }
  4523.       
  4524.       if (TREE_VOLATILE (parm))
  4525.     MEM_VOLATILE_P (DECL_RTL (parm)) = 1;
  4526.       if (TREE_READONLY (parm))
  4527.     RTX_UNCHANGING_P (DECL_RTL (parm)) = 1;
  4528.  
  4529.       /* Update info on where next arg arrives in registers.  */
  4530.  
  4531.       FUNCTION_ARG_ADVANCE (args_so_far, passed_mode, DECL_ARG_TYPE (parm), 1);
  4532.     }
  4533.  
  4534.   max_parm_reg = max_reg_num ();
  4535.   last_parm_insn = get_last_insn ();
  4536.  
  4537.   current_function_args_size = stack_args_size.constant;
  4538. }
  4539.  
  4540. /* Allocation of space for returned structure values.
  4541.    During the rtl generation pass, `get_structure_value_addr'
  4542.    is called from time to time to request the address of a block in our
  4543.    stack frame in which called functions will store the structures
  4544.    they are returning.  The same space is used for all of these blocks.  
  4545.  
  4546.    We allocate these blocks like stack locals.  We keep reusing
  4547.    the same block until a bigger one is needed.  */
  4548.  
  4549. /* Length in bytes of largest structure value returned by
  4550.    any function called so far in this function.  */
  4551. static int max_structure_value_size;
  4552.  
  4553. /* An rtx for the addr we are currently using for structure values.
  4554.    This is typically (PLUS (REG:SI stackptr) (CONST_INT...)).  */
  4555. static rtx structure_value;
  4556.  
  4557. rtx
  4558. get_structure_value_addr (sizex)
  4559.      rtx sizex;
  4560. {
  4561.   register int size;
  4562.   if (GET_CODE (sizex) != CONST_INT)
  4563.     abort ();
  4564.   size = INTVAL (sizex);
  4565.  
  4566.   /* Round up to a multiple of the main allocation unit.  */
  4567.   size = (((size + (BIGGEST_ALIGNMENT / BITS_PER_UNIT) - 1)
  4568.        / (BIGGEST_ALIGNMENT / BITS_PER_UNIT))
  4569.       * (BIGGEST_ALIGNMENT / BITS_PER_UNIT));
  4570.  
  4571.   /* If this size is bigger than space we know to use,
  4572.      get a bigger piece of space.  */
  4573.   if (size > max_structure_value_size)
  4574.     {
  4575.       max_structure_value_size = size;
  4576.       structure_value = assign_stack_local (BLKmode, size);
  4577.       if (GET_CODE (structure_value) == MEM)
  4578.     structure_value = XEXP (structure_value, 0);
  4579.     }
  4580.  
  4581.   return structure_value;
  4582. }
  4583.  
  4584. /* Walk the tree of LET_STMTs describing the binding levels within a function
  4585.    and warn about uninitialized variables.
  4586.    This is done after calling flow_analysis and before global_alloc
  4587.    clobbers the pseudo-regs to hard regs.  */
  4588.  
  4589. void
  4590. uninitialized_vars_warning (block)
  4591.      tree block;
  4592. {
  4593.   register tree decl, sub;
  4594.   for (decl = STMT_VARS (block); decl; decl = TREE_CHAIN (decl))
  4595.     {
  4596.       if (TREE_CODE (decl) == VAR_DECL
  4597.       /* These warnings are unreliable for and aggregates
  4598.          because assigning the fields one by one can fail to convince
  4599.          flow.c that the entire aggregate was initialized.
  4600.          Unions are troublesome because members may be shorter.  */
  4601.       && TREE_CODE (TREE_TYPE (decl)) != RECORD_TYPE
  4602.       && TREE_CODE (TREE_TYPE (decl)) != UNION_TYPE
  4603.       && TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE
  4604.       && DECL_RTL (decl) != 0
  4605.       && GET_CODE (DECL_RTL (decl)) == REG
  4606.       && regno_uninitialized (REGNO (DECL_RTL (decl))))
  4607.     warning_with_decl (decl,
  4608.                "`%s' may be used uninitialized in this function");
  4609.       if (TREE_CODE (decl) == VAR_DECL
  4610.       && DECL_RTL (decl) != 0
  4611.       && GET_CODE (DECL_RTL (decl)) == REG
  4612.       && regno_clobbered_at_setjmp (REGNO (DECL_RTL (decl))))
  4613.     warning_with_decl (decl,
  4614.                "variable `%s' may be clobbered by `longjmp'");
  4615.     }
  4616.   for (sub = STMT_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
  4617.     uninitialized_vars_warning (sub);
  4618. }
  4619.  
  4620. /* If this function call setjmp, put all vars into the stack
  4621.    unless they were declared `register'.  */
  4622.  
  4623. void
  4624. setjmp_protect (block)
  4625.      tree block;
  4626. {
  4627.   register tree decl, sub;
  4628.   for (decl = STMT_VARS (block); decl; decl = TREE_CHAIN (decl))
  4629.     if ((TREE_CODE (decl) == VAR_DECL
  4630.      || TREE_CODE (decl) == PARM_DECL)
  4631.     && DECL_RTL (decl) != 0
  4632.     && GET_CODE (DECL_RTL (decl)) == REG
  4633.     && ! TREE_REGDECL (decl))
  4634.       put_var_into_stack (decl);
  4635.   for (sub = STMT_SUBBLOCKS (block); sub; sub = TREE_CHAIN (sub))
  4636.     setjmp_protect (sub);
  4637. }
  4638.  
  4639. /* Generate RTL for the start of the function SUBR (a FUNCTION_DECL tree node)
  4640.    and initialize static variables for generating RTL for the statements
  4641.    of the function.  */
  4642.  
  4643. void
  4644. init_function_start (subr)
  4645.      tree subr;
  4646. {
  4647.   this_function = subr;
  4648.   cse_not_expected = ! optimize;
  4649.  
  4650.   /* We have not yet found a reason why a frame pointer cannot
  4651.      be omitted for this function in particular, but maybe we know
  4652.      a priori that it is required.
  4653.      `flag_omit_frame_pointer' has its main effect here.  */
  4654.   frame_pointer_needed = FRAME_POINTER_REQUIRED || ! flag_omit_frame_pointer;
  4655.  
  4656.   /* Caller save not needed yet.  */
  4657.   caller_save_needed = 0;
  4658.  
  4659.   /* No gotos have been expanded yet.  */
  4660.   goto_fixup_chain = 0;
  4661.  
  4662.   /* No stack slots have been made yet.  */
  4663.   stack_slot_list = 0;
  4664.  
  4665.   /* No invalid stack slots have been made yet.  */
  4666.   invalid_stack_slot = 0;
  4667.  
  4668.   /* No parm regs have been allocated.
  4669.      (This is important for output_inline_function.)  */
  4670.   max_parm_reg = FIRST_PSEUDO_REGISTER;
  4671.  
  4672.   /* Initialize the RTL mechanism.  */
  4673.   init_emit (write_symbols);
  4674.  
  4675.   /* Initialize the queue of pending postincrement and postdecrements,
  4676.      and some other info in expr.c.  */
  4677.   init_expr ();
  4678.  
  4679.   init_const_rtx_hash_table ();
  4680.  
  4681.   /* Decide whether function should try to pop its args on return.  */
  4682.  
  4683.   current_function_pops_args = RETURN_POPS_ARGS (TREE_TYPE (subr));
  4684.  
  4685.   current_function_name = (char *)lang_printable_name (subr);
  4686.  
  4687.   /* Nonzero if this is a nested function that uses a static chain.  */
  4688.  
  4689.   current_function_needs_context
  4690.     = (DECL_CONTEXT (current_function_decl) != 0
  4691.        && TREE_CODE (DECL_CONTEXT (current_function_decl)) == LET_STMT);
  4692.  
  4693.   /* Set if a call to setjmp is seen.  */
  4694.  
  4695.   current_function_calls_setjmp = 0;
  4696.   current_function_calls_alloca = 0;
  4697.  
  4698.   current_function_returns_pcc_struct = 0;
  4699.   current_function_returns_struct = 0;
  4700.  
  4701.   /* No space assigned yet for structure values.  */
  4702.   max_structure_value_size = 0;
  4703.   structure_value = 0;
  4704.  
  4705.   /* We are not currently within any block, conditional, loop or case.
  4706.      @@ No longer true.  We are within the block for the parms.  */
  4707.   block_stack = 0;
  4708.   loop_stack = 0;
  4709.   case_stack = 0;
  4710.   cond_stack = 0;
  4711.   nesting_stack = 0;
  4712.   nesting_depth = 0;
  4713.  
  4714.   block_start_count = 0;
  4715.  
  4716.   /* We have not yet needed to make a label to jump to for tail-recursion.  */
  4717.   tail_recursion_label = 0;
  4718.  
  4719.   /* No stack slots allocated yet.  */
  4720.   frame_offset = STARTING_FRAME_OFFSET;
  4721.  
  4722.   /* No SAVE_EXPRs in this function yet.  */
  4723.   save_expr_regs = 0;
  4724.  
  4725.   /* No parameters to protect from `__builtin_saveregs' yet.  */
  4726.   save_from_saveregs = 0;
  4727.  
  4728.   /* No RTL_EXPRs in this function yet.  */
  4729.   rtl_expr_chain = 0;
  4730.  
  4731.   /* Within function body, compute a type's size as soon it is laid out.  */
  4732.   immediate_size_expand++;
  4733.  
  4734.   init_pending_stack_adjust ();
  4735.   inhibit_defer_pop = 0;
  4736.   current_function_pretend_args_size = 0;
  4737.  
  4738.   /* Prevent ever trying to delete the first instruction of a function.
  4739.      Also tell final how to output a linenum before the function prologue.  */
  4740.   emit_line_note (DECL_SOURCE_FILE (subr), DECL_SOURCE_LINE (subr));
  4741.   /* Make sure first insn is a note even if we don't want linenums.
  4742.      This makes sure the first insn will never be deleted.
  4743.      Also, final expects a note to appear there.  */
  4744.   emit_note (0, NOTE_INSN_DELETED);
  4745.   /* Indicate the beginning of the function body,
  4746.      as opposed to parm setup.  */
  4747.   emit_note (0, NOTE_INSN_FUNCTION_BEG);
  4748.  
  4749.   /* Set flags used by final.c.  */
  4750.   if (aggregate_value_p (DECL_RESULT (subr)))
  4751.     {
  4752. #ifdef PCC_STATIC_STRUCT_RETURN
  4753.       if (flag_pcc_struct_return)
  4754.     current_function_returns_pcc_struct = 1;
  4755.       else
  4756. #endif
  4757.     current_function_returns_struct = 1;
  4758.     }
  4759. }
  4760.  
  4761. /* Start the RTL for a new function, and set variables used for
  4762.    emitting RTL.
  4763.    SUBR is the FUNCTION_DECL node.
  4764.    PARMS_HAVE_CLEANUPS is nonzero if there are cleanups associated with
  4765.    the function's parameters, which must be run at any return statement.  */
  4766.  
  4767. void
  4768. expand_function_start (subr, parms_have_cleanups)
  4769.      tree subr;
  4770.      int parms_have_cleanups;
  4771. {
  4772.   register int i;
  4773.   tree tem;
  4774.  
  4775.   /* Make sure volatile mem refs aren't considered
  4776.      valid operands of arithmetic insns.  */
  4777.   init_recog ();
  4778.  
  4779.   /* If the parameters of this function need cleaning up, get a label
  4780.      for the beginning of the code which executes those cleanups.  This must
  4781.      be done before doing anything with return_label.  */
  4782.   if (parms_have_cleanups)
  4783.     cleanup_label = gen_label_rtx ();
  4784.   else
  4785.     cleanup_label = 0;
  4786.  
  4787.   /* Make the label for return statements to jump to, if this machine
  4788.      does not have a one-instruction return and uses an epilogue,
  4789.      or if it returns a structure, or if it has parm cleanups.  */
  4790. #ifdef HAVE_return
  4791.   if (cleanup_label == 0 && HAVE_return
  4792.       && ! current_function_returns_pcc_struct
  4793.       && ! (current_function_returns_struct && ! optimize))
  4794.     return_label = 0;
  4795.   else
  4796.     return_label = gen_label_rtx ();
  4797. #else
  4798.   return_label = gen_label_rtx ();
  4799. #endif
  4800.  
  4801.   /* Initialize rtx used to return the value.  */
  4802.   /* Do this before assign_parms so that we copy the struct value address
  4803.      before any library calls that assign parms might generate.  */
  4804.  
  4805.   /* Decide whether to return the value in memory or in a register.  */
  4806.   if (aggregate_value_p (DECL_RESULT (subr)))
  4807.     {
  4808.       /* Returning something that won't go in a register.  */
  4809.       register rtx value_address;
  4810.  
  4811. #ifdef PCC_STATIC_STRUCT_RETURN
  4812.       if (flag_pcc_struct_return)
  4813.     {
  4814.       int size = int_size_in_bytes (TREE_TYPE (DECL_RESULT (subr)));
  4815.       value_address = assemble_static_space (size);
  4816.       current_function_returns_pcc_struct = 1;
  4817.     }
  4818.       else
  4819. #endif
  4820.     {
  4821.       /* Expect to be passed the address of a place to store the value.  */
  4822.       value_address = gen_reg_rtx (Pmode);
  4823.       emit_move_insn (value_address, struct_value_incoming_rtx);
  4824.       current_function_returns_struct = 1;
  4825.     }
  4826.       DECL_RTL (DECL_RESULT (subr))
  4827.     = gen_rtx (MEM, DECL_MODE (DECL_RESULT (subr)),
  4828.            value_address);
  4829.     }
  4830.   else if (DECL_MODE (DECL_RESULT (subr)) == VOIDmode)
  4831.     /* If return mode is void, this decl rtl should not be used.  */
  4832.     DECL_RTL (DECL_RESULT (subr)) = 0;
  4833.   else if (parms_have_cleanups)
  4834.     {
  4835.       /* If function will end with cleanup code for parms,
  4836.      compute the return values into a pseudo reg,
  4837.      which we will copy into the true return register
  4838.      after the cleanups are done.  */
  4839.       DECL_RTL (DECL_RESULT (subr))
  4840.     = gen_reg_rtx (DECL_MODE (DECL_RESULT (subr)));
  4841.       TREE_REGDECL (DECL_RESULT (subr)) = 1;
  4842.     }
  4843.   else
  4844.     /* Scalar, returned in a register.  */
  4845.     {
  4846. #ifdef FUNCTION_OUTGOING_VALUE
  4847.       DECL_RTL (DECL_RESULT (subr))
  4848.     = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
  4849. #else
  4850.       DECL_RTL (DECL_RESULT (subr))
  4851.     = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (subr)), subr);
  4852. #endif
  4853.  
  4854.       current_function_returns_pointer 
  4855.     = (TREE_CODE (TREE_TYPE (DECL_RESULT (subr))) == POINTER_TYPE);
  4856.  
  4857.       /* Mark this reg as the function's return value.  */
  4858.       if (GET_CODE (DECL_RTL (DECL_RESULT (subr))) == REG)
  4859.     {
  4860.       REG_FUNCTION_VALUE_P (DECL_RTL (DECL_RESULT (subr))) = 1;
  4861.       TREE_REGDECL (DECL_RESULT (subr)) = 1;
  4862.     }
  4863.     }
  4864.  
  4865.   /* Initialize rtx for parameters and local variables.
  4866.      In some cases this requires emitting insns.  */
  4867.  
  4868.   assign_parms (subr);
  4869.  
  4870. #if 0
  4871.   /* Not yet defined in GCC 1.37.1.  */
  4872.  
  4873.   /* Tell final that the parameters are in the final places
  4874.      (either on the stack or in registers).  */
  4875.   emit_note ((char *) 0, NOTE_INSN_PARMS_HOMED);
  4876. #endif
  4877.  
  4878.   /* If doing stupid allocation, mark parms as born here.  */
  4879.  
  4880.   if (GET_CODE (get_last_insn ()) != NOTE)
  4881.     emit_note (0, NOTE_INSN_DELETED);
  4882.   parm_birth_insn = get_last_insn ();
  4883.  
  4884.   if (obey_regdecls)
  4885.     {
  4886.       for (i = FIRST_PSEUDO_REGISTER; i < max_parm_reg; i++)
  4887.     use_variable (regno_reg_rtx[i]);
  4888.     }
  4889.  
  4890.   /* After the parm initializations is where the tail-recursion label
  4891.      should go, if we end up needing one.  */
  4892.   tail_recursion_reentry = get_last_insn ();
  4893.  
  4894.   /* Evaluate now the sizes of any types declared among the arguments.  */
  4895.   for (tem = get_pending_sizes (); tem; tem = TREE_CHAIN (tem))
  4896.     expand_expr (TREE_VALUE (tem), 0, VOIDmode, 0);
  4897.  
  4898.   /* Make sure there is a line number after the function entry setup code.
  4899.      There normally is one anyway, from the following statement,
  4900.      but there could fail to be one if there is no newline here.  */
  4901.   force_next_line_note ();
  4902. }
  4903.  
  4904. /* Generate RTL for the end of the current function.
  4905.    FILENAME and LINE are the current position in the source file.  */
  4906.  
  4907. /* ??? Nobody seems to emit the cleanup_label and the cleanups themselves.
  4908.  
  4909.    !!! Not true.  finish_function does this is cplus-decl.c.  */
  4910.  
  4911. void
  4912. expand_function_end (filename, line)
  4913.      char *filename;
  4914.      int line;
  4915. {
  4916.   register int i;
  4917.   tree decl;
  4918.   extern rtx sequence_stack;
  4919.  
  4920. #if 0  /* I think unused parms are legitimate enough.  */
  4921.   /* Warn about unused parms.  */
  4922.   if (warn_unused)
  4923.     for (decl = DECL_ARGUMENTS (current_function_decl);
  4924.      decl; decl = TREE_CHAIN (decl))
  4925.       if (! TREE_USED (decl) && TREE_CODE (decl) == VAR_DECL)
  4926.     warning_with_decl (decl, "unused parameter `%s'");
  4927. #endif
  4928.  
  4929.   /* End any sequences that failed to be closed due to syntax errors.  */
  4930.   while (sequence_stack)
  4931.     end_sequence (0);
  4932.  
  4933.   /* Outside function body, can't compute type's actual size
  4934.      until next function's body starts.  */
  4935.   immediate_size_expand--;
  4936.  
  4937.   /* If doing stupid register allocation,
  4938.      mark register parms as dying here.  */
  4939.  
  4940.   if (obey_regdecls)
  4941.     {
  4942.       rtx tem;
  4943.       for (i = FIRST_PSEUDO_REGISTER; i < max_parm_reg; i++)
  4944.     use_variable (regno_reg_rtx[i]);
  4945.  
  4946.       /* Likewise for the regs of all the SAVE_EXPRs in the function.  */
  4947.  
  4948.       for (tem = save_expr_regs; tem; tem = XEXP (tem, 1))
  4949.     {
  4950.       use_variable (XEXP (tem, 0));
  4951.       use_variable_after (XEXP (tem, 0), parm_birth_insn);
  4952.     }
  4953.     }
  4954.  
  4955.   clear_pending_stack_adjust ();
  4956.   do_pending_stack_adjust ();
  4957.  
  4958.   /* Mark the end of the function body.
  4959.      If control reaches this insn, the function can drop through
  4960.      without returning a value.  */
  4961.   emit_note (0, NOTE_INSN_FUNCTION_END);
  4962.  
  4963.   /* Output a linenumber for the end of the function.
  4964.      SDB depends on this.  */
  4965.   emit_line_note_force (filename, line);
  4966.  
  4967.   /* Output the label for the actual return from the function,
  4968.      if one is expected.  This happens either because a function epilogue
  4969.      is used instead of a return instruction, or because a return was done
  4970.      with a goto in order to run local cleanups, or because of pcc-style
  4971.      structure returning.  */
  4972.  
  4973.   if (return_label)
  4974.     emit_label (return_label);
  4975.  
  4976.   /* If we had calls to alloca, and this machine needs
  4977.      an accurate stack pointer to exit the function,
  4978.      insert some code to save and restore the stack pointer.  */
  4979. #ifdef EXIT_IGNORE_STACK
  4980.   if (! EXIT_IGNORE_STACK)
  4981. #endif
  4982.     if (current_function_calls_alloca)
  4983.       {
  4984.     rtx tem = gen_reg_rtx (Pmode);
  4985.     emit_insn_after (gen_rtx (SET, VOIDmode, tem, stack_pointer_rtx),
  4986.              parm_birth_insn);
  4987.     emit_insn (gen_rtx (SET, VOIDmode, stack_pointer_rtx, tem));
  4988.       }
  4989.  
  4990.   /* If scalar return value was computed in a pseudo-reg,
  4991.      copy that to the hard return register.  */
  4992.   if (DECL_RTL (DECL_RESULT (current_function_decl)) != 0
  4993.       && GET_CODE (DECL_RTL (DECL_RESULT (current_function_decl))) == REG
  4994.       && (REGNO (DECL_RTL (DECL_RESULT (current_function_decl)))
  4995.       >= FIRST_PSEUDO_REGISTER))
  4996.     {
  4997.       rtx real_decl_result;
  4998.  
  4999. #ifdef FUNCTION_OUTGOING_VALUE
  5000.       real_decl_result
  5001.     = FUNCTION_OUTGOING_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
  5002.                    current_function_decl);
  5003. #else
  5004.       real_decl_result
  5005.     = FUNCTION_VALUE (TREE_TYPE (DECL_RESULT (current_function_decl)),
  5006.               current_function_decl);
  5007. #endif
  5008.       REG_FUNCTION_VALUE_P (real_decl_result) = 1;
  5009.       emit_move_insn (real_decl_result,
  5010.               DECL_RTL (DECL_RESULT (current_function_decl)));
  5011.       emit_insn (gen_rtx (USE, VOIDmode, real_decl_result));
  5012.     }
  5013.  
  5014.   /* If returning a structure, arrange to return the address of the value
  5015.      in a place where debuggers expect to find it.  */
  5016.   /* If returning a structure PCC style,
  5017.      the caller also depends on this value.
  5018.      And current_function_returns_pcc_struct is not necessarily set.  */
  5019.   if (current_function_returns_struct
  5020.       || current_function_returns_pcc_struct)
  5021.     {
  5022.       rtx value_address = XEXP (DECL_RTL (DECL_RESULT (current_function_decl)), 0);
  5023.       tree type = TREE_TYPE (DECL_RESULT (current_function_decl));
  5024. #ifdef FUNCTION_OUTGOING_VALUE
  5025.       rtx outgoing
  5026.     = FUNCTION_OUTGOING_VALUE (build_pointer_type (type),
  5027.                    current_function_decl);
  5028. #else
  5029.       rtx outgoing
  5030.     = hard_function_value (build_pointer_type (type),
  5031.                    current_function_decl);
  5032. #endif
  5033.  
  5034. #if 1
  5035.       /* If this works, leave it in.  */
  5036.       /* This is not really the function value,
  5037.      and it confuses integrate.c around line 1211.  */
  5038.       REG_FUNCTION_VALUE_P (outgoing) = 1;
  5039. #endif
  5040.  
  5041.       emit_move_insn (outgoing, value_address);
  5042.       use_variable (outgoing);
  5043.     }
  5044.  
  5045.   /* Output a return insn if we are using one.
  5046.      Otherwise, let the rtl chain end here, to drop through
  5047.      into the epilogue.  */
  5048.  
  5049. #ifdef HAVE_return
  5050.   if (HAVE_return)
  5051.     emit_jump_insn (gen_return ());
  5052. #endif
  5053.  
  5054.   /* Fix up any gotos that jumped out to the outermost
  5055.      binding level of the function.
  5056.      Must follow emitting RETURN_LABEL.  */
  5057.  
  5058.   /* If you have any cleanups to do at this point,
  5059.      and they need to create temporary variables,
  5060.      then you will lose.  */
  5061.   fixup_gotos (0, 0, 0, get_insns (), 0);
  5062. }
  5063.  
  5064. init_stmt ()
  5065. {
  5066.   obstack_init (&stmt_obstack);
  5067. }
  5068.